Re: FD_SETSIZE with large #s of files/ports in use

Поиск
Список
Период
Сортировка
От Hiroshi Inoue
Тема Re: FD_SETSIZE with large #s of files/ports in use
Дата
Msg-id 4BF477DA.8000208@tpf.co.jp
обсуждение исходный текст
Ответ на Re: FD_SETSIZE with large #s of files/ports in use  (Hiroshi Inoue <inoue@tpf.co.jp>)
Ответы Re: FD_SETSIZE with large #s of files/ports in use  ("B. Nicholson" <b.nicholson@niceng.com>)
Re: FD_SETSIZE with large #s of files/ports in use  ("B. Nicholson" <b.nicholson@niceng.com>)
Список pgsql-odbc
Hiroshi Inoue wrote:
> Hiroshi Inoue wrote:
>> Hi,
>>
>> Could you please try the attached patch?
>
> Oops it doesn't seem to work.
> Another way is to use poll() instead of select().

OK I made a patch to use poll().
Please #define HAVE_POLL e.g. in config.h and try the attached patch.

regards,
Hiroshi Inoue
diff -c ../psqlodbc/socket.c ./socket.c
*** ../psqlodbc/socket.c    2010-01-11 09:56:18.605000000 +0900
--- ./socket.c    2010-05-19 17:03:10.874000000 +0900
***************
*** 350,357 ****
--- 350,362 ----
      if (connect(self->socket, (struct sockaddr *) &(self->sadr_area), self->sadr_len) < 0)
      {
          int    ret, optval;
+         int    wait_sec = 0;
+ #ifdef    HAVE_POLL
+         struct pollfd fds;
+ #else
          fd_set    fds, except_fds;
          struct    timeval    tm;
+ #endif /* HAVE_POLL */
          socklen_t    optlen = sizeof(optval);
          time_t    t_now, t_finish = 0;
          BOOL    tm_exp = FALSE;
***************
*** 377,391 ****
          {
              t_now = time(NULL);
              t_finish = t_now + timeout;
!             tm.tv_sec = timeout;
!             tm.tv_usec = 0;
          }
          do {
              FD_ZERO(&fds);
              FD_ZERO(&except_fds);
              FD_SET(self->socket, &fds);
              FD_SET(self->socket, &except_fds);
              ret = select((int) self->socket + 1, NULL, &fds, &except_fds, timeout > 0 ? &tm : NULL);
              gerrno = SOCK_ERRNO;
              if (0 < ret)
                  break;
--- 382,404 ----
          {
              t_now = time(NULL);
              t_finish = t_now + timeout;
!             wait_sec = timeout;
          }
          do {
+ #ifdef    HAVE_POLL
+             fds.fd = self->socket;
+             fds.events = POLLOUT;
+             fds.revents = 0;
+             ret = poll(&fds, 1, timeout > 0 ? wait_sec * 1000 : -1);
+ #else
+             tm.tv_sec = wait_sec;
+             tm.tv_usec = 0;
              FD_ZERO(&fds);
              FD_ZERO(&except_fds);
              FD_SET(self->socket, &fds);
              FD_SET(self->socket, &except_fds);
              ret = select((int) self->socket + 1, NULL, &fds, &except_fds, timeout > 0 ? &tm : NULL);
+ #endif /* HAVE_POLL */
              gerrno = SOCK_ERRNO;
              if (0 < ret)
                  break;
***************
*** 398,407 ****
                  if (t_now = time(NULL), t_now >= t_finish)
                      tm_exp = TRUE;
                  else
!                 {
!                     tm.tv_sec = (long) (t_finish - t_now);
!                     tm.tv_usec = 0;
!                 }
              }
          } while (!tm_exp);
          if (tm_exp)
--- 411,417 ----
                  if (t_now = time(NULL), t_now >= t_finish)
                      tm_exp = TRUE;
                  else
!                     wait_sec = t_finish - t_now;
              }
          } while (!tm_exp);
          if (tm_exp)
***************
*** 475,482 ****
--- 485,496 ----
  static int SOCK_wait_for_ready(SocketClass *sock, BOOL output, int retry_count)
  {
      int    ret, gerrno;
+ #ifdef    HAVE_POLL
+     struct pollfd    fds;
+ #else
      fd_set    fds, except_fds;
      struct    timeval    tm;
+ #endif /* HAVE_POLL */
      BOOL    no_timeout = TRUE;

      if (0 == retry_count)
***************
*** 488,493 ****
--- 502,513 ----
          no_timeout = TRUE;
  #endif /* USE_SSL */
      do {
+ #ifdef    HAVE_POLL
+         fds.fd = sock->socket;
+         fds.events = output ? POLLOUT : POLLIN;
+         fds.revents = 0;
+         ret = poll(&fds, 1, no_timeout ? -1 : retry_count * 1000);
+ #else
          FD_ZERO(&fds);
          FD_ZERO(&except_fds);
          FD_SET(sock->socket, &fds);
***************
*** 498,503 ****
--- 518,524 ----
              tm.tv_usec = 0;
          }
          ret = select((int) sock->socket + 1, output ? NULL : &fds, output ? &fds : NULL, &except_fds, no_timeout ?
NULL: &tm); 
+ #endif /* HAVE_POLL */
          gerrno = SOCK_ERRNO;
      } while (ret < 0 && EINTR == gerrno);
      if (retry_count < 0)
diff -c ../psqlodbc/socket.h ./socket.h
*** ../psqlodbc/socket.h    2010-01-11 09:56:31.371000000 +0900
--- ./socket.h    2010-05-19 13:15:50.157000000 +0900
***************
*** 21,26 ****
--- 21,29 ----

  #ifndef WIN32
  #define    WSAAPI
+ #ifdef    HAVE_POLL
+ #include <poll.h>
+ #endif /* HAVE_POLL_H */
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <sys/un.h>

В списке pgsql-odbc по дате отправления:

Предыдущее
От: Hiroshi Inoue
Дата:
Сообщение: Re: FD_SETSIZE with large #s of files/ports in use
Следующее
От: "B. Nicholson"
Дата:
Сообщение: Re: FD_SETSIZE with large #s of files/ports in use