]> git.tue.mpg.de Git - paraslash.git/commitdiff
kill duplicate write_ok()
authorAndre <maan@p133.(none)>
Fri, 24 Mar 2006 19:05:34 +0000 (20:05 +0100)
committerAndre <maan@p133.(none)>
Fri, 24 Mar 2006 19:05:34 +0000 (20:05 +0100)
use the generic inline function from send.h instead and shutdown the
connection if an error occured in write_ok().

dccp_send.c
http_send.c
send.h

index 5478c1d19a23210ae719a4f0c80e9cca56376541..c7805f735b02c096083058d269ee4b0d2ee6b759 100644 (file)
@@ -122,7 +122,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);
@@ -130,10 +135,19 @@ 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);
index c574ba3ca91f58c5114f08e4191c624898bd1a04..73d2fb0d51f6d63663387e16a1b2b574f7024bd7 100644 (file)
@@ -178,23 +178,6 @@ static int queue_packet(struct http_client *hc, const char *buf, size_t len)
        return 1;
 }
 
-static int write_ok(int fd)
-{
-       struct timeval tv = {0, 0};
-       fd_set wfds;
-       int ret;
-again:
-       FD_ZERO(&wfds);
-       FD_SET(fd, &wfds);
-       ret = select(fd + 1, NULL, &wfds, NULL, &tv);
-       if (ret < 0 && errno == EINTR)
-               goto again;
-       if (ret < 0)
-               ret = -E_WRITE_OK;
-       return ret;
-}
-
-
 static int send_queued_packets(struct http_client *hc)
 {
        int ret;
@@ -205,7 +188,7 @@ static int send_queued_packets(struct http_client *hc)
        list_for_each_entry_safe(qp, tmp, &hc->packet_queue, node) {
                ret = write_ok(hc->fd);
                if (ret <= 0)
-                       return ret;
+                       return ret? -E_WRITE_OK : 0;
                ret = write(hc->fd, qp->packet, qp->len);
                if (ret < 0)
                        return ret;
diff --git a/send.h b/send.h
index 75c13731bb1af9223a0a32fdc8c85792f04f3d50..3aebb1600ebfdee0450c0100ae8c99921c7c0cd0 100644 (file)
--- a/send.h
+++ b/send.h
@@ -85,9 +85,16 @@ struct sender {
        int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
 };
 
+/**
+ * check a file descriptor for writability
+ *
+ * \param fd the file desctiptor
+ *
+ * \return positive if fd is ready for writing, zero if it isn't, negative if
+ * an error occured.
+ */
 
-
-static inline int _write_ok(int fd)
+static inline int write_ok(int fd)
 {
        struct timeval tv = {0, 0};
        fd_set wfds;
@@ -98,8 +105,5 @@ again:
        ret = select(fd + 1, NULL, &wfds, NULL, &tv);
        if (ret < 0 && errno == EINTR)
                goto again;
-       if (ret < 0)
-               ret = 0;
        return ret;
 }
-