diff --git a/lib/libc/include/nscachedcli.h b/lib/libc/include/nscachedcli.h --- a/lib/libc/include/nscachedcli.h +++ b/lib/libc/include/nscachedcli.h @@ -29,6 +29,8 @@ #ifndef __NS_CACHED_CLI_H__ #define __NS_CACHED_CLI_H__ +#include + /* * This file contains API for working with caching daemon */ @@ -66,6 +68,8 @@ int mp_flag; /* shows if the connection is used for * multipart operations */ + bool eof; + int last_status; }; /* simple abstractions for not to write "struct" every time */ @@ -85,6 +89,7 @@ /* initialization/destruction routines */ extern cached_connection __open_cached_connection( struct cached_connection_params const *); +extern void __end_cached_connection(cached_connection); extern void __close_cached_connection(cached_connection); /* simple read/write operations */ @@ -103,6 +108,7 @@ extern cached_mp_read_session __open_cached_mp_read_session( struct cached_connection_params const *, const char *); extern int __cached_mp_read(cached_mp_read_session, char *, size_t *); +extern int __end_cached_mp_read_session(cached_mp_read_session); extern int __close_cached_mp_read_session(cached_mp_read_session); __END_DECLS diff --git a/lib/libc/net/nscache.c b/lib/libc/net/nscache.c --- a/lib/libc/net/nscache.c +++ b/lib/libc/net/nscache.c @@ -30,6 +30,7 @@ #include "namespace.h" #define _NS_PRIVATE #include +#include #include #include #include "un-namespace.h" @@ -288,6 +289,9 @@ cache_info->set_mp_rs_func(rs); } + if (rs->eof) { + return (rs->last_status); + } buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); @@ -314,10 +318,10 @@ res = 0; } else { free(buffer); - __close_cached_mp_read_session(rs); - rs = INVALID_CACHED_MP_READ_SESSION; - cache_info->set_mp_rs_func(rs); - return (res == 1 ? NS_NOTFOUND : NS_UNAVAIL); + __end_cached_mp_read_session(rs); + rs->eof = true; + rs->last_status = res == 1 ? NS_NOTFOUND : NS_UNAVAIL; + return (rs->last_status); } free(buffer); diff --git a/lib/libc/net/nscachedcli.c b/lib/libc/net/nscachedcli.c --- a/lib/libc/net/nscachedcli.c +++ b/lib/libc/net/nscachedcli.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -233,13 +234,23 @@ } void -__close_cached_connection(struct cached_connection_ *connection) +__end_cached_connection(struct cached_connection_ *connection) { assert(connection != NULL); _close(connection->sockfd); + connection->sockfd = -1; _close(connection->read_queue); + connection->read_queue = -1; _close(connection->write_queue); + connection->write_queue = -1; + connection->eof = true; +} + +void +__close_cached_connection(struct cached_connection_ *connection) +{ + __end_cached_connection(connection); free(connection); } @@ -570,3 +581,11 @@ __close_cached_connection(rs); return (0); } + +int +__end_cached_mp_read_session(struct cached_connection_ *rs) +{ + + __end_cached_connection(rs); + return (0); +}