Index: asterisk/manager.c =================================================================== RCS file: /usr/cvsroot/asterisk/manager.c,v retrieving revision 1.37 diff -u -r1.37 manager.c --- asterisk/manager.c 29 Jan 2004 00:28:51 -0000 1.37 +++ asterisk/manager.c 6 Feb 2004 22:13:45 -0000 @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -727,6 +730,7 @@ struct mansession *s; struct protoent *p; int arg = 1; + int flags; pthread_attr_t attr; pthread_attr_init(&attr); @@ -744,6 +748,10 @@ if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) { ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\n", strerror(errno)); } + flags = fcntl(as, F_GETFL, 0) | O_NONBLOCK|O_NDELAY; + if( fcntl(as, F_SETFL, flags) ) { + ast_log(LOG_WARNING, "Failed to make manager connection non-blocking: %s\n", strerror(errno)); + } } s = malloc(sizeof(struct mansession)); if (!s) { @@ -781,8 +789,12 @@ va_start(ap, fmt); vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); - write(s->fd, tmp, strlen(tmp)); - ast_cli(s->fd, "\r\n"); + if (write(s->fd, tmp, strlen(tmp)) == -1) { + ast_verbose(VERBOSE_PREFIX_2 "Write error for manager '%s' from %s\n", + s->username, inet_ntoa(s->sin.sin_addr)); + } else { + ast_cli(s->fd, "\r\n"); + } } ast_mutex_unlock(&s->lock); }