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

Side by Side Diff: Modules/socketmodule.c

Issue 22043: Use a monotonic clock to compute timeouts
Patch Set: Created 3 years 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
« no previous file with comments | « Modules/gcmodule.c ('k') | Modules/timemodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 _PyTime_timeval 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 _PyTime_monotonic(&now); \
684 deadline = now; \ 684 deadline = now; \
685 _PyTime_ADD_SECONDS(deadline, s->sock_timeout); \ 685 _PyTime_ADD_SECONDS(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 _PyTime_monotonic(&now); \
695 interval = _PyTime_INTERVAL(now, deadline); \ 695 interval = _PyTime_INTERVAL(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,
(...skipping 6299 matching lines...) Expand 10 before | Expand all | Expand 10 after
7004 return NULL; 7004 return NULL;
7005 memcpy(&packed_addr, src, sizeof(packed_addr)); 7005 memcpy(&packed_addr, src, sizeof(packed_addr));
7006 return strncpy(dst, inet_ntoa(packed_addr), size); 7006 return strncpy(dst, inet_ntoa(packed_addr), size);
7007 } 7007 }
7008 /* Should set errno to EAFNOSUPPORT */ 7008 /* Should set errno to EAFNOSUPPORT */
7009 return NULL; 7009 return NULL;
7010 } 7010 }
7011 7011
7012 #endif 7012 #endif
7013 #endif 7013 #endif
OLDNEW
« no previous file with comments | « Modules/gcmodule.c ('k') | Modules/timemodule.c » ('j') | no next file with comments »

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