X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=dccp_send.c;h=57e2a70ccb30b0cef8550fd288991ef005d30b1e;hb=96ba5d16111ffb0e4814f1e786cbd53ce3121bd2;hp=dd495f98eccb190fc8aff579cf7851d5bcf627d8;hpb=f9149914884d8348ae0dca36aa47478da921ac8b;p=paraslash.git diff --git a/dccp_send.c b/dccp_send.c index dd495f98..57e2a70c 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -16,6 +16,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ +/* + * based on server.c of dccp-cs-0.01.tar.bz2, + * (C) 2005 Ian McDonald + */ + #include "server.h" #include "net.h" #include "list.h" @@ -59,14 +64,13 @@ static void dccp_post_select(__unused struct audio_format *af, fd_set *rfds, if (!FD_ISSET(listen_fd, rfds)) return; - PARA_NOTICE_LOG("%s", "accepting...\n"); dc = para_calloc(sizeof(struct dccp_client)); ret = para_accept(listen_fd, &dc->addr, sizeof(struct sockaddr_in)); if (ret < 0) { PARA_ERROR_LOG("%s", PARA_STRERROR(-ret)); return; } - PARA_NOTICE_LOG("%s", "connection\n"); + PARA_NOTICE_LOG("connection from %s\n", inet_ntoa(dc->addr.sin_addr)); dc->fd = ret; list_add(&dc->node, &clients); } @@ -117,7 +121,12 @@ static void dccp_send(__unused struct audio_format *af, return; list_for_each_entry_safe(dc, tmp, &clients, node) { - if (!_write_ok(dc->fd)) + ret = write_ok(dc->fd); + if (ret < 0) { + dccp_shutdown_client(dc); + continue; + } + if (!ret) continue; if (!dc->header_sent && af->get_header_info && current_chunk) { header_buf = af->get_header_info(&header_len); @@ -125,13 +134,22 @@ static void dccp_send(__unused struct audio_format *af, continue; /* header not yet available */ ret = write(dc->fd, header_buf, header_len); if (ret != header_len) { + int err = errno; + PARA_ERROR_LOG("header write: %d/%d (%s)\n", + ret, header_len, ret < 0? + strerror(err) : ""); + dccp_shutdown_client(dc); + continue; + } + ret = write_ok(dc->fd); + if (ret < 0) { dccp_shutdown_client(dc); continue; } - if (!_write_ok(dc->fd)) + if (!ret) continue; } - PARA_DEBUG_LOG("writing %d bytes to fd %d\n", len, dc->fd); +// PARA_DEBUG_LOG("writing %d bytes to fd %d\n", len, dc->fd); ret = write(dc->fd, buf, len); if (ret != len) dccp_shutdown_client(dc); @@ -155,7 +173,7 @@ static char *dccp_info(void) free(buf); list_for_each_entry_safe(dc, tmp, &clients, node) num_clients++; - buf = make_message("%d connected clients\n", num_clients); + buf = make_message("dccp connected clients: %d\n", num_clients); return buf; }