Merge "res_pjsip_mwi: Turn some NOTICEs and WARNINGs into debug 1s."
[asterisk/asterisk.git] / utils / streamplayer.c
index fb0d055..809bd64 100644 (file)
@@ -19,7 +19,7 @@
 /*!
  * \file
  * \author Russell Bryant <russell@digium.com>
- * 
+ *
  * \brief A utility for reading from a raw TCP stream
  *
  * This application is intended for use when a raw TCP stream is desired to be
  * not work.  :)
  */
 
+/*** MODULEINFO
+       <support_level>extended</support_level>
+ ***/
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -80,40 +84,43 @@ int main(int argc, char *argv[])
        }
 
        memset(&sin, 0, sizeof(sin));
-       
+
        sin.sin_family = AF_INET;
        sin.sin_port = htons(atoi(argv[2]));
        memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
-       
+
        s = socket(AF_INET, SOCK_STREAM, 0);
-       
+
        if (s < 0) {
                fprintf(stderr, "Unable to allocate socket!\n");
                exit(1);
-       }       
+       }
 
        res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
-       
+
        if (res) {
                fprintf(stderr, "Unable to connect to host!\n");
                close(s);
-               exit(1);        
+               exit(1);
        }
 
        while (1) {
                res = read(s, buf, sizeof(buf));
 
                if (res < 1)
-                       break;          
-       
-               memset(&tv, 0, sizeof(tv));             
+                       break;
+
+               memset(&tv, 0, sizeof(tv));
                FD_ZERO(&wfds);
                FD_SET(1, &wfds);
 
                select(2, NULL, &wfds, NULL, &tv);
 
-               if (FD_ISSET(1, &wfds))
-                       write(1, buf, res);
+               if (FD_ISSET(1, &wfds)) {
+                       if (write(1, buf, res) < 1) {
+                               break;
+                       }
+               }
        }
 
        close(s);