diff options
author | Simo Sorce <simo@redhat.com> | 2012-01-18 16:38:45 -0500 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2012-01-19 15:18:39 -0500 |
commit | 2510be0abeb21d185a13e023abb9e62a774a769b (patch) | |
tree | 347a81a8d48ebd63dff140ffdad36664b95dcbc1 /proxy/src | |
parent | cb1ab5633b112e083fa252712f8fc667373a93af (diff) | |
download | gss-proxy-2510be0abeb21d185a13e023abb9e62a774a769b.tar.gz gss-proxy-2510be0abeb21d185a13e023abb9e62a774a769b.tar.xz gss-proxy-2510be0abeb21d185a13e023abb9e62a774a769b.zip |
Prefix replies on the wire with the packet size
Diffstat (limited to 'proxy/src')
-rw-r--r-- | proxy/src/gp_socket.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/proxy/src/gp_socket.c b/proxy/src/gp_socket.c index 3c80142..ea8ae19 100644 --- a/proxy/src/gp_socket.c +++ b/proxy/src/gp_socket.c @@ -365,12 +365,39 @@ void gp_socket_send_data(verto_ctx *vctx, struct gp_conn *conn, static void gp_socket_write(verto_ctx *vctx, verto_ev *ev) { struct gp_buffer *wbuf; + uint32_t size; ssize_t wn; int fd; fd = verto_get_fd(ev); wbuf = verto_get_private(ev); + if (wbuf->pos == 0) { + /* first write, send the buffer size as packet header */ + size = htonl(wbuf->size); + + errno = 0; + wn = write(fd, &size, sizeof(uint32_t)); + if (wn == -1) { + if (errno == EAGAIN || errno == EINTR) { + /* try again later */ + gp_socket_schedule_write(vctx, wbuf); + } else { + /* error on socket, close and release it */ + gp_conn_free(wbuf->conn); + gp_buffer_free(wbuf); + } + return; + } + if (wn != 4) { + /* don't bother trying to handle sockets that can't + * buffer even 4 bytes */ + gp_conn_free(wbuf->conn); + gp_buffer_free(wbuf); + return; + } + } + errno = 0; wn = write(fd, wbuf->data + wbuf->pos, wbuf->size - wbuf->pos); if (wn == -1) { |