@@ -53,6 +53,14 @@ int UnixsocketConnector::recv_message(rapidjson::Document &output) {
53
53
s_output = " " ;
54
54
55
55
while ((t.tv_sec - t0.tv_sec )*1000 + (t.tv_usec - t0.tv_usec )/1000 < this ->timeout ) {
56
+ int avail = waitForData (this ->fd , 0 , this ->timeout * 500 ); // use half the timeout as poll timeout
57
+ if (avail < 0 ) // poll error
58
+ return -1 ;
59
+ if (avail == 0 ) { // timeout
60
+ gettimeofday (&t, NULL );
61
+ continue ;
62
+ }
63
+
56
64
std::string temp;
57
65
temp.clear ();
58
66
@@ -110,7 +118,7 @@ ssize_t UnixsocketConnector::write(const std::string &data) {
110
118
nbuf = data.copy (buf, sizeof buf, pos); // copy data and write
111
119
nwrite = ::write (fd, buf, nbuf);
112
120
pos = pos + sizeof (buf);
113
- if (nwrite == - 1 ) {
121
+ if (nwrite < 1 ) {
114
122
connected = false ;
115
123
close (fd);
116
124
return -1 ;
@@ -141,17 +149,7 @@ void UnixsocketConnector::reconnect() {
141
149
return ;
142
150
}
143
151
144
- if (fcntl (fd, F_SETFL, O_NONBLOCK, &fd)) {
145
- connected = false ;
146
- L<<Logger::Error<<" Cannot manipulate socket: " << strerror (errno) << std::endl;;
147
- close (fd);
148
- return ;
149
- }
150
-
151
- if ((rv = connect (fd, reinterpret_cast <struct sockaddr *>(&sock), sizeof sock))==-1 && (errno == EINPROGRESS)) {
152
- waitForData (fd, 0 , -1 );
153
- rv = connect (fd, reinterpret_cast <struct sockaddr *>(&sock), sizeof sock);
154
- }
152
+ rv = connect (fd, reinterpret_cast <struct sockaddr *>(&sock), sizeof sock);
155
153
156
154
if (rv != 0 && errno != EISCONN && errno != 0 ) {
157
155
L<<Logger::Error<<" Cannot connect to socket: " << strerror (errno) << std::endl;
0 commit comments