- if (fgets(buf, 255, stdin)==NULL) strcpy(buf, "000");
- if (strcmp(buf, "000")) serv_puts(buf);
- } while (strcmp(buf, "000"));
- }
+ if (fgets(buf, sizeof buf, stdin) == NULL)
+ strcpy(buf, "000");
+ if (strlen(buf) > 0)
+ if (buf[strlen(buf) - 1] == '\n')
+ buf[strlen(buf) - 1] = 0;
+ if (strlen(buf) > 0)
+ if (buf[strlen(buf) - 1] == '\r')
+ buf[strlen(buf) - 1] = 0;
+ if (strcmp(buf, "000"))
+ CtdlIPC_chat_send(ipc, buf);
+
+ FD_ZERO(&read_fd);
+ FD_SET(ipc->sock, &read_fd);
+ ret = select(ipc->sock+1, &read_fd, NULL, NULL, &tv);
+ err = errno;
+ if (err!=0)
+ printf("select failed: %d", err);
+
+ if (ret == -1) {
+ if (!(errno == EINTR || errno == EAGAIN))
+ printf("select failed: %d", err);
+ return 1;
+ }
+
+ if (ret != 0) {
+ size_t n;
+ char rbuf[SIZ];