MCPcopy Create free account
hub / github.com/Tencent/phxsql / RoutineWriteWithTimeout

Function RoutineWriteWithTimeout

phxsqlproxy/routineutil.cpp:87–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87int RoutineWriteWithTimeout(int dest_fd, const char * buf, int write_size, int timeout_ms) {
88 assert(IsNonBlock(dest_fd));
89 int written_once = 0;
90
91 written_once = write(dest_fd, buf, write_size);
92 if (written_once > 0) {
93 return written_once;
94 }
95
96 if (written_once <= 0) {
97 if (errno == EAGAIN || errno == EINTR) {
98 written_once = 0;
99 } else {
100 return -__LINE__;
101 }
102 }
103
104 struct pollfd pf[1];
105 int nfds = 0;
106 memset(pf, 0, sizeof(pf));
107 pf[0].fd = dest_fd;
108 pf[0].events = (POLLOUT | POLLERR | POLLHUP);
109 nfds++;
110
111 int return_fd_count = co_poll(co_get_epoll_ct(), pf, nfds, timeout_ms);
112 if (return_fd_count < 0) {
113 return return_fd_count;
114 }
115
116 if (pf[0].revents & POLLOUT) {
117 written_once = write(dest_fd, buf, write_size);
118 if (written_once <= 0) {
119 if (errno == EAGAIN || errno == EINTR) {
120 written_once = 0;
121 } else {
122 return written_once;
123 }
124 }
125 } else if (pf[0].revents & POLLHUP) {
126 return return_fd_count;
127 } else if (pf[0].revents & POLLERR) {
128 return return_fd_count;
129 }
130 return written_once;
131}
132
133int RoutinePeekWithTimeout(int source_fd, char * buf, int buf_size, int timeout_ms) {
134 assert(IsNonBlock(source_fd));

Callers 3

SendProxyHeaderMethod · 0.85
AssignFDMethod · 0.85
WriteToDestMethod · 0.85

Calls 1

IsNonBlockFunction · 0.85

Tested by

no test coverage detected