diff options
| author | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-05-27 20:21:19 -0400 |
|---|---|---|
| committer | Nalin Dahyabhai <nalin.dahyabhai@pobox.com> | 2008-05-27 20:21:19 -0400 |
| commit | beaf6734f8a8589c9213d8c95e58d98a417c2aaf (patch) | |
| tree | 2a64bd7ac68d3c2a3312acd0ba4a13768d68591a /src/dispatch.c | |
| parent | b64ae5cb2f3adb40da0a61ddba1eb0d71f12b2b5 (diff) | |
| download | slapi-nis-beaf6734f8a8589c9213d8c95e58d98a417c2aaf.tar.gz slapi-nis-beaf6734f8a8589c9213d8c95e58d98a417c2aaf.tar.xz slapi-nis-beaf6734f8a8589c9213d8c95e58d98a417c2aaf.zip | |
- pass the entire client structure to connected reply callbacks
Diffstat (limited to 'src/dispatch.c')
| -rw-r--r-- | src/dispatch.c | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/src/dispatch.c b/src/dispatch.c index 38197cc..d453d71 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -26,10 +26,40 @@ #define MAX_CLIENT_IDLE (60 * 1000) -struct dispatch_client_data { - int client; +/* Handle all incoming data. */ +struct dispatch_client { + /* The client socket and address. */ + int client_fd; struct sockaddr client_addr; socklen_t client_addrlen; + /* The client state. */ + enum { + client_invalid, + client_closing, + client_reading, + client_replying_with_more, + client_replying_final, + } client_state; + /* The client's request while we're reading it. */ + char client_inbuf[8192]; + ssize_t client_inbuf_used; + char *client_query; + ssize_t client_query_size; + void *client_query_cookie; + /* The reply to the client, when we're sending one. */ + char client_outbuf[4096]; + ssize_t client_outbuf_used; + /* This is a linked list. */ + struct dispatch_client *client_next; +}; + +struct dispatch_client_data { + struct dispatch_client *connected; + struct { + int client_fd; + struct sockaddr client_addr; + socklen_t client_addrlen; + } dgram; }; /* Send a reply, unbuffered datagram version. */ @@ -52,8 +82,8 @@ dispatch_reply_fragment_dgram(struct plugin_state *state, "Sending datagram reply (%d bytes).\n", xdr_getpos(reply_xdrs)); } - sendto(cdata->client, reply_buf, xdr_getpos(reply_xdrs), - 0, &cdata->client_addr, cdata->client_addrlen); + sendto(cdata->dgram.client_fd, reply_buf, xdr_getpos(reply_xdrs), + 0, &cdata->dgram.client_addr, cdata->dgram.client_addrlen); return TRUE; } static bool_t @@ -134,7 +164,7 @@ dispatch_reply_fragment_connected(struct plugin_state *state, len = htonl(xdr_getpos(reply_xdrs) | (last_fragment ? 0x80000000 : 0)); /* Send the data to the client. */ - if (dispatch_write_with_retry(state, cdata->client, + if (dispatch_write_with_retry(state, cdata->connected->client_fd, &len, 4, reply_buf, xdr_getpos(reply_xdrs)) == @@ -153,7 +183,7 @@ dispatch_reply_fragment_connected(struct plugin_state *state, } } /* Send an entire reply record at once. */ -bool_t +static bool_t dispatch_reply_connected(struct plugin_state *state, struct dispatch_client_data *cdata, struct rpc_msg *reply, @@ -173,10 +203,11 @@ dispatch_dgram(struct plugin_state *state, int fd) int reqsize; /* Read the request. */ - cdata.client = fd; - cdata.client_addrlen = sizeof(cdata.client_addr); - reqsize = recvfrom(fd, dgram, sizeof(dgram), 0, - &cdata.client_addr, &cdata.client_addrlen); + cdata.dgram.client_fd = fd; + cdata.dgram.client_addrlen = sizeof(cdata.dgram.client_addr); + reqsize = recvfrom(cdata.dgram.client_fd, dgram, sizeof(dgram), 0, + &cdata.dgram.client_addr, + &cdata.dgram.client_addrlen); slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id, "datagram request (%d bytes)\n", reqsize); @@ -187,33 +218,6 @@ dispatch_dgram(struct plugin_state *state, int fd) &cdata, NULL); } -/* Handle all incoming data. */ -struct dispatch_client { - /* The client socket and address. */ - int client_fd; - struct sockaddr client_addr; - socklen_t client_addrlen; - /* The client state. */ - enum { - client_invalid, - client_closing, - client_reading, - client_replying_with_more, - client_replying_final, - } client_state; - /* The client's request while we're reading it. */ - char client_inbuf[8192]; - ssize_t client_inbuf_used; - char *client_query; - ssize_t client_query_size; - void *client_query_cookie; - /* The reply to the client, when we're sending one. */ - char client_outbuf[4096]; - ssize_t client_outbuf_used; - /* This is a linked list. */ - struct dispatch_client *client_next; -}; - /* Set the client's record up to start reading a new query. */ static void client_set_reading(struct plugin_state *state, struct dispatch_client *client) @@ -368,10 +372,8 @@ client_read(struct plugin_state *state, struct dispatch_client *client) client->client_query_size, client->client_fd); /* We have a complete query. Pass it on down. */ - client_data.client = client->client_fd; - memset(&client_data.client_addr, 0, - sizeof(client_data.client_addr)); - client_data.client_addrlen = 0; + memset(&client_data, 0, sizeof(client_data)); + client_data.connected = client; nis_process_request(state, client->client_query, client->client_query_size, @@ -414,9 +416,8 @@ client_write(struct plugin_state *state, struct dispatch_client *client) } else { /* More to send, so ask for more reply data. */ client->client_outbuf_used = 0; - client_data.client = client->client_fd; - client_data.client_addr = client->client_addr; - client_data.client_addrlen = client->client_addrlen; + memset(&client_data, 0, sizeof(client_data)); + client_data.connected = client; nis_process_request(state, client->client_query, client->client_query_size, |
