]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fs_cli: refactor out stdout_writeable()
authorTravis Cross <tc@traviscross.com>
Thu, 22 Sep 2011 04:13:13 +0000 (04:13 +0000)
committerTravis Cross <tc@traviscross.com>
Fri, 23 Sep 2011 01:25:41 +0000 (01:25 +0000)
libs/esl/fs_cli.c

index 96e6d6995b1a4ae75da864be9e4a30313c98db09..2404785f8864de953d6cbd6482bedb47410169f7 100644 (file)
@@ -518,6 +518,27 @@ static int usage(char *name){
        return 1;
 }
 
+static int stdout_writable(void)
+{
+#ifndef WIN32
+       fd_set set;
+       int fd = fileno(stdout);
+       struct timeval to;
+       memset(&to, 0, sizeof(to));
+       FD_ZERO(&set);
+       FD_SET(fd, &set);
+       to.tv_sec = 0;
+       to.tv_usec = 100000;
+       if (select(fd + 1, NULL, &set, NULL, &to) > 0) {
+               return FD_ISSET(fd, &set);
+       } else {
+               return 0;
+       }
+#else
+       return 1;
+#endif
+}
+
 static void *msg_thread_run(esl_thread_t *me, void *obj)
 {
        esl_handle_t *handle = (esl_handle_t *) obj;
@@ -529,21 +550,7 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
                        if (aok) esl_log(ESL_LOG_WARNING, "Disconnected.\n");
                        running = -1; thread_running = 0;
                } else if (status == ESL_SUCCESS) {
-#ifndef WIN32
-                       fd_set can_write;
-                       int fd = fileno(stdout);
-                       struct timeval to;
-                       memset(&to, 0, sizeof(to));
-                       FD_ZERO(&can_write);
-                       FD_SET(fd, &can_write);
-                       to.tv_sec = 0;
-                       to.tv_usec = 100000;
-                       if (select(fd + 1, NULL, &can_write, NULL, &to) > 0) {
-                               aok = FD_ISSET(fd, &can_write);
-                       } else {
-                               aok = 0;
-                       }
-#endif
+                       aok = stdout_writable();
                        if (handle->last_event) {
                                int known = 1;
                                const char *type = esl_event_get_header(handle->last_event, "content-type");