- } else if (buf[0] == '4') {
- do {
- if (fgets(buf, sizeof buf, stdin) == NULL)
- strcpy(buf, "000");
- if (!IsEmptyStr(buf))
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = 0;
- if (!IsEmptyStr(buf))
- 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];
-
- rbuf[0] = '\0';
- n = read(ipc->sock, rbuf, SIZ);
- if (n>0) {
- rbuf[n]='\0';
- fprintf (stderr, rbuf);
- fflush (stdout);
- }
- }
- alarm(watchdog); /* Kick the watchdog timer */
- } while (strcmp(buf, "000"));
- CtdlIPC_chat_send(ipc, "\n");
- CtdlIPC_chat_send(ipc, "000");