From: <n-...@us...> - 2010-11-26 02:30:26
|
Revision: 4942 http://gfarm.svn.sourceforge.net/gfarm/?rev=4942&view=rev Author: n-soda Date: 2010-11-26 02:30:20 +0000 (Fri, 26 Nov 2010) Log Message: ----------- add gfp_xdr_vsend_async_nonblocking_request() function as a preparation of #142 - generic send queue for backchannel is necessary in gfmd. Part of this implementation is also needed for #143 - reading/writing a transaction file in gfmd Modified Paths: -------------- gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.c gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.h gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr_server.c gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.c gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.h Modified: gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.c =================================================================== --- gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.c 2010-11-25 12:05:00 UTC (rev 4941) +++ gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.c 2010-11-26 02:30:20 UTC (rev 4942) @@ -118,7 +118,18 @@ return (conn->fd); } +gfarm_error_t +gfp_xdr_sendbuffer_check_size(struct gfp_xdr *conn, int size) +{ + if (size > gfarm_iobuffer_get_size(conn->sendbuffer)) + return (GFARM_ERR_NO_BUFFER_SPACE_AVAILABLE); + else if (size > gfarm_iobuffer_avail_length(conn->sendbuffer)) + return (GFARM_ERR_RESOURCE_TEMPORARILY_UNAVAILABLE); + else + return (GFARM_ERR_NO_ERROR); +} + gfarm_error_t gfp_xdr_export_credential(struct gfp_xdr *conn) { Modified: gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.h =================================================================== --- gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.h 2010-11-25 12:05:00 UTC (rev 4941) +++ gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr.h 2010-11-26 02:30:20 UTC (rev 4942) @@ -24,6 +24,7 @@ (e) == GFARM_ERR_NETWORK_IS_UNREACHABLE || \ (e) == GFARM_ERR_CONNECTION_ABORTED || \ (e) == GFARM_ERR_CONNECTION_RESET_BY_PEER || \ + (e) == GFARM_ERR_NO_BUFFER_SPACE_AVAILABLE || \ (e) == GFARM_ERR_SOCKET_IS_NOT_CONNECTED || \ (e) == GFARM_ERR_OPERATION_TIMED_OUT || \ (e) == GFARM_ERR_CONNECTION_REFUSED || \ @@ -35,6 +36,7 @@ void *gfp_xdr_cookie(struct gfp_xdr *); int gfp_xdr_fd(struct gfp_xdr *); +gfarm_error_t gfp_xdr_sendbuffer_check_size(struct gfp_xdr *, int); void gfp_xdr_set(struct gfp_xdr *, struct gfp_iobuffer_ops *, void *, int); Modified: gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr_server.c =================================================================== --- gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr_server.c 2010-11-25 12:05:00 UTC (rev 4941) +++ gfarm_v2/trunk/lib/libgfarm/gfarm/gfp_xdr_server.c 2010-11-26 02:30:20 UTC (rev 4942) @@ -141,6 +141,7 @@ gfarm_mutex_unlock(&async_server->mutex, diag, async_peer_diag); xid_and_type = (xid | XID_TYPE_REQUEST); +#define ASYNC_REQUEST_HEADER_SIZE (4+4) /* size of "ii" */ e = gfp_xdr_send(server, "ii", xid_and_type, (gfarm_int32_t)size); if (e != GFARM_ERR_NO_ERROR) { gfp_xdr_send_async_request_error(async_server, xid, diag); @@ -151,12 +152,13 @@ } /* this does gfp_xdr_flush() too, for freeing xid in an error case */ -gfarm_error_t -gfp_xdr_vsend_async_request(struct gfp_xdr *server, +static gfarm_error_t +gfp_xdr_vsend_async_request_internal(struct gfp_xdr *server, gfp_xdr_async_peer_t async_server, gfarm_int32_t (*result_callback)(void *, void *, size_t), void (*disconnect_callback)(void *, void *), void *closure, + int nonblock, gfarm_int32_t command, const char *format, va_list *app) { gfarm_error_t e; @@ -176,6 +178,10 @@ if (e != GFARM_ERR_NO_ERROR) return (e); + if (nonblock && (e = gfp_xdr_sendbuffer_check_size(server, + size + ASYNC_REQUEST_HEADER_SIZE)) != GFARM_ERR_NO_ERROR) + return (e); + e = gfp_xdr_send_async_request_header(server, async_server, size, result_callback, disconnect_callback, closure, &xid); if (e != GFARM_ERR_NO_ERROR) @@ -200,6 +206,32 @@ return (GFARM_ERR_NO_ERROR); } +gfarm_error_t +gfp_xdr_vsend_async_nonblocking_request(struct gfp_xdr *server, + gfp_xdr_async_peer_t async_server, + gfarm_int32_t (*result_callback)(void *, void *, size_t), + void (*disconnect_callback)(void *, void *), + void *closure, + gfarm_int32_t command, const char *format, va_list *app) +{ + return (gfp_xdr_vsend_async_request_internal(server, + async_server, result_callback, disconnect_callback, closure, 1, + command, format, app)); +} + +gfarm_error_t +gfp_xdr_vsend_async_request(struct gfp_xdr *server, + gfp_xdr_async_peer_t async_server, + gfarm_int32_t (*result_callback)(void *, void *, size_t), + void (*disconnect_callback)(void *, void *), + void *closure, + gfarm_int32_t command, const char *format, va_list *app) +{ + return (gfp_xdr_vsend_async_request_internal(server, + async_server, result_callback, disconnect_callback, closure, 0, + command, format, app)); +} + /* * used by both client and server side */ Modified: gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.c =================================================================== --- gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.c 2010-11-25 12:05:00 UTC (rev 4941) +++ gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.c 2010-11-26 02:30:20 UTC (rev 4942) @@ -75,6 +75,12 @@ free(b); } +int +gfarm_iobuffer_get_size(struct gfarm_iobuffer *b) +{ + return (b->bufsize); +} + void gfarm_iobuffer_set_error(struct gfarm_iobuffer *b, int error) { Modified: gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.h =================================================================== --- gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.h 2010-11-25 12:05:00 UTC (rev 4941) +++ gfarm_v2/trunk/lib/libgfarm/gfarm/iobuffer.h 2010-11-26 02:30:20 UTC (rev 4942) @@ -55,6 +55,7 @@ struct gfarm_iobuffer *gfarm_iobuffer_alloc(int); void gfarm_iobuffer_free(struct gfarm_iobuffer *); +int gfarm_iobuffer_get_size(struct gfarm_iobuffer *); void gfarm_iobuffer_set_error(struct gfarm_iobuffer *, int); int gfarm_iobuffer_get_error(struct gfarm_iobuffer *); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |