Beispiel #1
0
void str_cli(FILE *fp, int sockfd) {
    fd_set rset;
    char buff[MAXLINE];

    fb_zero(&set);
    int stdineof = 0;
    while (true) {
        if (stdineof == 0)
            fb_set(fileno(fp), &rset);
        fb_set(sockfd, &rset);
        int maxfp = max(fileno(fp), sockfd) + 1;
        lx_select(maxfp, &rset, NULL, NULL, NULL);

        if (fb_isset(sockfd, &rset)) {
            if (lx_readline(sockfd, recvline, MAXLINE) == 0)
                lx_err_quit("str_cli: server terminated prematurely");
            lx_fputs(recvline, stdout);
        }
        if (fb_isset(fileno(fp), &rest)) {
            if (fb_fgets(sendline, MAXLINE, fp) == NULL)
                return;
            lx_writen(sockfd, sendline, strlen(sendline));
        }
    }
}
Beispiel #2
0
unsigned int lx_msleep(unsigned int mseconds)
{
  struct lx_timeval tv;

  tv.tv_sec  = 0;
  tv.tv_usec = mseconds * 1000;
  if (lx_select(1, NULL, NULL, NULL, &tv) < 0)
    return 0;

  return tv.tv_sec;
}