Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(7)

Side by Side Diff: Modules/socketmodule.c

Issue 22043: Use a monotonic clock to compute timeouts
Patch Set: Created 5 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Socket module */ 1 /* Socket module */
2 2
3 /* 3 /*
4 4
5 This module provides an interface to Berkeley socket IPC. 5 This module provides an interface to Berkeley socket IPC.
6 6
7 Limitations: 7 Limitations:
8 8
9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a 9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a
10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported 10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 Py_END_ALLOW_THREADS 669 Py_END_ALLOW_THREADS
670 if (timeout == 1) { 670 if (timeout == 1) {
671 PyErr_SetString(socket_timeout, "timed out"); 671 PyErr_SetString(socket_timeout, "timed out");
672 return -1; 672 return -1;
673 } 673 }
674 END_SELECT_LOOP(s) 674 END_SELECT_LOOP(s)
675 */ 675 */
676 676
677 #define BEGIN_SELECT_LOOP(s) \ 677 #define BEGIN_SELECT_LOOP(s) \
678 { \ 678 { \
679 _PyTime_timeval now, deadline = {0, 0}; \ 679 _PyTimeSpec now, deadline = {0, 0}; \
680 double interval = s->sock_timeout; \ 680 double interval = s->sock_timeout; \
681 int has_timeout = s->sock_timeout > 0.0; \ 681 int has_timeout = s->sock_timeout > 0.0; \
682 if (has_timeout) { \ 682 if (has_timeout) { \
683 _PyTime_gettimeofday(&now); \ 683 _PyTimeSpec_get_time(&now); \
684 deadline = now; \ 684 deadline = now; \
685 _PyTime_ADD_SECONDS(deadline, s->sock_timeout); \ 685 _PyTimeSpec_add_sec(&deadline, s->sock_timeout); \
686 } \ 686 } \
687 while (1) { \ 687 while (1) { \
688 errno = 0; \ 688 errno = 0; \
689 689
690 #define END_SELECT_LOOP(s) \ 690 #define END_SELECT_LOOP(s) \
691 if (!has_timeout || \ 691 if (!has_timeout || \
692 (!CHECK_ERRNO(EWOULDBLOCK) && !CHECK_ERRNO(EAGAIN))) \ 692 (!CHECK_ERRNO(EWOULDBLOCK) && !CHECK_ERRNO(EAGAIN))) \
693 break; \ 693 break; \
694 _PyTime_gettimeofday(&now); \ 694 _PyTimeSpec_get_time(&now); \
695 interval = _PyTime_INTERVAL(now, deadline); \ 695 interval = _PyTimeSpec_interval_sec(&now, &deadline); \
696 } \ 696 } \
697 } \ 697 } \
698 698
699 /* Initialize a new socket object. */ 699 /* Initialize a new socket object. */
700 700
701 static double defaulttimeout = -1.0; /* Default timeout for new sockets */ 701 static double defaulttimeout = -1.0; /* Default timeout for new sockets */
702 702
703 static void 703 static void
704 init_sockobject(PySocketSockObject *s, 704 init_sockobject(PySocketSockObject *s,
705 SOCKET_T fd, int family, int type, int proto) 705 SOCKET_T fd, int family, int type, int proto)
(...skipping 6232 matching lines...) Expand 10 before | Expand all | Expand 10 after
6938 return NULL; 6938 return NULL;
6939 memcpy(&packed_addr, src, sizeof(packed_addr)); 6939 memcpy(&packed_addr, src, sizeof(packed_addr));
6940 return strncpy(dst, inet_ntoa(packed_addr), size); 6940 return strncpy(dst, inet_ntoa(packed_addr), size);
6941 } 6941 }
6942 /* Should set errno to EAFNOSUPPORT */ 6942 /* Should set errno to EAFNOSUPPORT */
6943 return NULL; 6943 return NULL;
6944 } 6944 }
6945 6945
6946 #endif 6946 #endif
6947 #endif 6947 #endif
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+