sin.sin_addr.s_addr = INADDR_ANY;
if (port_number == 0) {
- printf("webcit: Cannot start: no port number specified.\n");
+ fprintf(stderr,
+ "webcit: Cannot start: no port number specified.\n");
exit(1);
}
sin.sin_port = htons((u_short) port_number);
s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
if (s < 0) {
- printf("webcit: Can't create a socket: %s\n",
+ fprintf(stderr, "webcit: Can't create a socket: %s\n",
strerror(errno));
exit(errno);
}
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
- printf("webcit: Can't bind: %s\n", strerror(errno));
+ fprintf(stderr, "webcit: Can't bind: %s\n", strerror(errno));
exit(errno);
}
if (listen(s, queue_len) < 0) {
- printf("webcit: Can't listen: %s\n", strerror(errno));
+ fprintf(stderr, "webcit: Can't listen: %s\n", strerror(errno));
exit(errno);
}
return (s);
retval = write(sock, &buf[bytes_written],
nbytes - bytes_written);
if (retval < 1) {
- printf("client_write() failed: %s\n",
+ fprintf(stderr, "client_write() failed: %s\n",
strerror(errno));
- pthread_exit(NULL);
}
bytes_written = bytes_written + retval;
}
}
rlen = read(sock, &buf[len], bytes - len);
if (rlen < 1) {
- printf("client_read() failed: %s\n",
+ fprintf(stderr, "client_read() failed: %s\n",
strerror(errno));
- pthread_exit(NULL);
}
len = len + rlen;
}
* There is no need to check for errors, because ig_tcp_server()
* exits if it doesn't succeed.
*/
- printf("Attempting to bind to port %d...\n", port);
+ fprintf(stderr, "Attempting to bind to port %d...\n", port);
msock = ig_tcp_server(port, 5);
- printf("Listening on socket %d\n", msock);
+ fprintf(stderr, "Listening on socket %d\n", msock);
signal(SIGPIPE, SIG_IGN);
pthread_mutex_init(&SessionListMutex, NULL);
if (pthread_create(&SessThread, &attr,
(void *(*)(void *)) worker_entry, NULL)
!= 0) {
- printf("webcit: can't create thread: %s\n",
+ fprintf(stderr, "webcit: can't create thread: %s\n",
strerror(errno));
}
}
ssock = accept(msock, (struct sockaddr *) &fsin, &alen);
pthread_mutex_unlock(&AcceptQueue);
- printf("New connection on socket %d\n", ssock);
if (ssock < 0) {
- printf("webcit: accept() failed: %s\n",
+ fprintf(stderr, "webcit: accept() failed: %s\n",
strerror(errno));
} else {
/* Set the SO_REUSEADDR socket option */