i = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
- fcntl(s, F_SETFL, O_NONBLOCK);/// TODO
+ fcntl(s, F_SETFL, O_NONBLOCK); /* maide: this statement is incorrect
+ there should be a preceding F_GETFL
+ and a bitwise OR with the previous
+ fd flags */
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
lprintf(1, "Can't bind: %s\n", strerror(errno));
*/
ssize_t client_write(const void *buf, size_t count)
{
- char *newptr;
- size_t newalloc;
+ char *newptr;
+ size_t newalloc;
+ size_t bytesWritten = 0;
+ ssize_t res;
+ fd_set wset;
+ int fdflags;
if (WC->burst != NULL) {
if ((WC->burst_len + count) >= WC->burst_alloc) {
write(2, buf, count);
write(2, "\033[30m", 5);
#endif
- return (write(WC->http_sock, buf, count));
+ fdflags = fcntl(WC->http_sock, F_GETFL);
+
+ while (bytesWritten < count) {
+ if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
+ FD_ZERO(&wset);
+ FD_SET(WC->http_sock, &wset);
+ if (select(1, NULL, &wset, NULL, NULL) == -1) {
+ lprintf(2, "client_write: Socket select failed (%s)\n", strerror(errno));
+ return -1;
+ }
+ }
+
+ if ((res = write(WC->http_sock, (char*)buf + bytesWritten,
+ count - bytesWritten)) == -1) {
+ lprintf(2, "client_write: Socket write failed (%s)\n", strerror(errno));
+ return res;
+ }
+ bytesWritten += res;
+ }
+
+ return bytesWritten;
}
/*
strcpy(uds_listen_path, "");
- if (getenv("TZ") == NULL)
- putenv("TZ=UTC");
-
/* Parse command line */
#ifdef HAVE_OPENSSL
while ((a = getopt(argc, argv, "h:i:p:t:x:dD:cfs")) != EOF)
free(mo);
lprintf(9, "Text domain: %s\n", textdomain("webcit"));
lprintf(9, "Text domain Charset: %s\n", bind_textdomain_codeset("webcit","UTF8"));
+ preset_locale();
#endif
lprintf(9, "Changing directory to %s\n", socket_dir);
if (chdir(webcitdir) != 0) {
perror("chdir");
- }
+ }
initialize_viewdefs();
initialize_axdefs();