Changeset c346b2
- Timestamp:
- 10/05/08 13:49:56 (4 years ago)
- Branches:
- master
- Children:
- e61b4e
- Parents:
- 46fd4a
- git-author:
- Tomash Brechko <tomash.brechko@…> (10/04/08 15:44:14)
- git-committer:
- Tomash Brechko <tomash.brechko@…> (10/05/08 13:49:56)
- Files:
-
- 2 added
- 8 edited
-
Changes (modified) (2 diffs)
-
MANIFEST (modified) (1 diff)
-
src/Makefile.PL (modified) (2 diffs)
-
src/client.c (modified) (13 diffs)
-
src/connect.c (modified) (4 diffs)
-
src/poll_select.c (added)
-
src/poll_select.h (added)
-
src/socket_posix.c (modified) (1 diff)
-
src/socket_posix.h (modified) (1 diff)
-
src/socket_win32.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
Changes
r46fd4a rc346b2 3 3 0.13 ??? 4 4 - introduce Win32 support (based on the patch by Yasuhiro 5 Matsumoto---arigatou!). 5 Matsumoto---arigatou!), and use poll() instead of select() 6 (suggested by Vladimir Timofeev). 6 7 7 8 Changes since 0.12: … … 10 11 compiler, so I can't even test the build. Win32 port is 11 12 expected to be supported by community. 13 14 Use poll() system call instead of select(). The latter has 15 the limit on the file descriptor value. I.e. even when the 16 number of memcached servers is low, if your application opens 17 lots of other files, then after some point socket() returns 18 fd value larger that select() can handle. poll() doesn't have 19 this limitation. On a side note, we don't have to use 20 advanced calls like epoll()/kqueue(), because number of 21 memcached servers is normally not very large (and single 22 request touches even a smaller subset). 12 23 13 24 -
MANIFEST
r46fd4a rc346b2 38 38 src/socket_win32.c 39 39 src/socket_win32.h 40 src/poll_select.c 41 src/poll_select.h -
src/Makefile.PL
r46fd4a rc346b2 5 5 6 6 7 my $includes = '/usr/include'; 8 my @define; 7 9 my @c = ('parse_keyword.c', 'compute_crc32.c', <*.c>); 8 my $exclude;10 my %exclude; 9 11 if ($^O eq 'MSWin32') { 10 $exclude = 'socket_posix.c';12 ++$exclude{'socket_posix.c'}; 11 13 } else { 12 $exclude = 'socket_win32.c'; 14 ++$exclude{'socket_win32.c'}; 15 16 if (-f "$includes/poll.h") { 17 push @define, '-DHAVE_POLL_H'; 18 ++$exclude{'poll_select.c'}; 19 } elsif (-f "$includes/sys/poll.h") { 20 push @define, '-DHAVE_SYS_POLL_H'; 21 ++$exclude{'poll_select.c'}; 22 } 13 23 } 14 24 15 my @object = grep { $_ ne $exclude} @c;25 my @object = grep { not exists $exclude{$_} } @c; 16 26 map { s/\.c$/\$(OBJ_EXT)/ } @object; 17 27 … … 24 34 AUTHOR => 'Tomash Brechko <tomash.brechko@gmail.com>', 25 35 LIBS => [''], # e.g., '-lm' 26 DEFINE => '', # e.g., '-DHAVE_SOMETHING'36 DEFINE => "@define", # e.g., '-DHAVE_SOMETHING' 27 37 INC => '-I.', # e.g., '-I. -I/usr/include/other' 28 38 OBJECT => "@object", -
src/client.c
r46fd4a rc346b2 105 105 struct client *client; 106 106 int fd; 107 struct pollfd *pollfd; 107 108 enum socket_mode_e socket_mode; 108 109 int noreply; … … 249 250 struct client 250 251 { 252 struct array pollfds; 251 253 struct array servers; 252 254 … … 350 352 return NULL; 351 353 354 array_init(&c->pollfds); 352 355 array_init(&c->servers); 353 356 array_init(&c->index_list); … … 394 397 395 398 array_destroy(&c->servers); 399 array_destroy(&c->pollfds); 396 400 array_destroy(&c->index_list); 397 401 array_destroy(&c->str_buf); … … 423 427 client_set_connect_timeout(struct client *c, int to) 424 428 { 425 c->connect_timeout = to;429 c->connect_timeout = (to > 0 ? to : -1); 426 430 } 427 431 … … 430 434 client_set_io_timeout(struct client *c, int to) 431 435 { 432 c->io_timeout = to;436 c->io_timeout = (to > 0 ? to : -1); 433 437 } 434 438 … … 477 481 478 482 if (weight <= 0.0) 483 return MEMCACHED_FAILURE; 484 485 if (array_extend(c->pollfds, struct pollfd, 1, ARRAY_EXTEND_EXACT) == -1) 479 486 return MEMCACHED_FAILURE; 480 487 … … 492 499 return MEMCACHED_FAILURE; 493 500 501 array_push(c->pollfds); 494 502 array_push(c->servers); 495 503 … … 1380 1388 client_execute(struct client *c) 1381 1389 { 1382 struct timeval to, *pto = c->io_timeout > 0 ? &to : NULL;1383 fd_set write_set, read_set;1384 1390 int first_iter = 1; 1385 1391 … … 1399 1405 { 1400 1406 struct server *s; 1401 int max_fd, res; 1402 1403 max_fd = -1; 1407 struct pollfd *pollfd_beg, *pollfd; 1408 int nfds, res; 1409 1410 nfds = 0; 1404 1411 for (array_each(c->servers, struct server, s)) 1405 1412 { … … 1420 1427 else 1421 1428 { 1422 may_write = FD_ISSET(state->fd, &write_set); 1423 may_read = FD_ISSET(state->fd, &read_set); 1429 const short revents = state->pollfd->revents; 1430 1431 may_write = revents & (POLLOUT | POLLERR | POLLHUP); 1432 may_read = revents & (POLLIN | POLLERR | POLLHUP); 1424 1433 } 1425 1434 … … 1446 1455 1447 1456 if (is_active(state)) 1448 { 1449 if (max_fd < state->fd) 1450 max_fd = state->fd; 1451 } 1457 ++nfds; 1452 1458 } 1453 1459 else 1454 1460 { 1455 if (max_fd < state->fd) 1456 max_fd = state->fd; 1461 ++nfds; 1457 1462 } 1458 1463 } 1459 1464 1460 if ( max_fd == -1)1465 if (nfds == 0) 1461 1466 break; 1462 1467 1463 FD_ZERO(&write_set); 1464 FD_ZERO(&read_set); 1468 pollfd_beg = array_beg(c->pollfds, struct pollfd); 1469 pollfd = pollfd_beg; 1470 1465 1471 for (array_each(c->servers, struct server, s)) 1466 1472 { … … 1469 1475 if (is_active(state)) 1470 1476 { 1477 pollfd->events = 0; 1478 1471 1479 if (state->iov_count > 0) 1472 FD_SET(state->fd, &write_set);1480 pollfd->events |= POLLOUT; 1473 1481 if (state->reply_count > 0 || state->nowait_count > 0) 1474 FD_SET(state->fd, &read_set); 1482 pollfd->events |= POLLIN; 1483 1484 if (pollfd->events != 0) 1485 { 1486 pollfd->fd = state->fd; 1487 state->pollfd = pollfd; 1488 ++pollfd; 1489 } 1475 1490 } 1476 1491 } 1477 1492 1478 1493 do 1479 { 1480 /* 1481 For maximum portability across systems that may or may not 1482 modify the timeout argument we treat it as undefined after 1483 the call, and reinitialize on every iteration. 1484 */ 1485 if (pto) 1486 { 1487 pto->tv_sec = c->io_timeout / 1000; 1488 pto->tv_usec = (c->io_timeout % 1000) * 1000; 1489 } 1490 res = select(max_fd + 1, &read_set, &write_set, NULL, pto); 1491 } 1494 res = poll(pollfd_beg, pollfd - pollfd_beg, c->io_timeout); 1492 1495 while (res == -1 && errno == EINTR); 1493 1496 -
src/connect.c
r46fd4a rc346b2 36 36 int timeout) 37 37 { 38 struct timeval to, *pto;39 38 struct addrinfo hint, *addr, *a; 40 39 int fd = -1, res; 41 42 pto = timeout > 0 ? &to : NULL;43 40 44 41 memset(&hint, 0, sizeof(hint)); … … 62 59 for (a = addr; a != NULL; a = a->ai_next) 63 60 { 64 fd_set write_set;61 struct pollfd pollfd; 65 62 int socket_error; 66 63 socklen_t socket_error_len; … … 69 66 if (fd == -1) 70 67 break; 68 69 if (! can_poll_fd(fd)) 70 { 71 close(fd); 72 fd = -1; 73 break; 74 } 71 75 72 76 res = set_nonblock(fd); … … 88 92 } 89 93 90 FD_ZERO(&write_set);91 FD_SET(fd, &write_set);94 pollfd.fd = fd; 95 pollfd.events = POLLOUT; 92 96 do 93 { 94 if (pto) 95 { 96 pto->tv_sec = timeout / 1000; 97 pto->tv_usec = (timeout % 1000) * 1000; 98 } 99 res = select(fd + 1, NULL, &write_set, NULL, pto); 100 } 97 res = poll(&pollfd, 1, timeout); 101 98 while (res == -1 && errno == EINTR); 102 99 if (res <= 0) -
src/socket_posix.c
r11df21 rc346b2 58 58 return -1; 59 59 60 if (! can_poll_fd(fd)) 61 { 62 close(fd); 63 64 return -1; 65 } 66 60 67 s_unix.sun_family = AF_UNIX; 61 68 memcpy(s_unix.sun_path, path, path_len); -
src/socket_posix.h
r11df21 rc346b2 31 31 #include <errno.h> 32 32 33 #if defined(HAVE_POLL_H) 34 35 #include <poll.h> 36 37 #define can_poll_fd(fd) 1 38 39 #elif defined(HAVE_SYS_POLL_H) 40 41 #include <sys/poll.h> 42 43 #define can_poll_fd(fd) 1 44 45 #else /* ! defined(HAVE_POLL_H) && ! defined(HAVE_SYS_POLL_H) */ 46 47 #include "poll_select.h" 48 49 #define poll(fds, nfds, timeout) poll_select(fds, nfds, timeout) 50 51 #endif /* ! defined(HAVE_POLL_H) && ! defined(HAVE_SYS_POLL_H) */ 52 33 53 34 54 extern -
src/socket_win32.h
r46fd4a rc346b2 31 31 #include <ws2tcpip.h> 32 32 #include <sys/types.h> 33 34 #if _WIN32_WINNT >= 0x0600 35 36 #define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) 37 38 #define can_poll_fd(fd) 1 39 40 #else /* ! (_WIN32_WINNT >= 0x0600) */ 41 42 #include "poll_select.h" 43 44 #define poll(fds, nfds, timeout) poll_select(fds, nfds, timeout) 45 46 #endif /* ! (_WIN32_WINNT >= 0x0600) */ 33 47 34 48
Note: See TracChangeset
for help on using the changeset viewer.
