summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2011-05-20 15:06:09 +0200
committerGravatar waker <wakeroid@gmail.com>2011-05-20 15:06:09 +0200
commita03b76d9fdd644d210439190a06002e31a9751e9 (patch)
tree42a72a5ec0ef8fe890f2ceb6bd0264f93a37f24d
parente428b96440c7f0bf43aae8ff47b5c3bd05c47025 (diff)
patched libmms to support connection timeout after 3 seconds
-rw-r--r--plugins/mms/libmms/mms.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/plugins/mms/libmms/mms.c b/plugins/mms/libmms/mms.c
index 7e0d4a07..e23c70db 100644
--- a/plugins/mms/libmms/mms.c
+++ b/plugins/mms/libmms/mms.c
@@ -204,7 +204,7 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port)
return -1;
}
- if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) & ~O_NONBLOCK) == -1) {
+ if (fcntl (s, F_SETFL, fcntl (s, F_GETFL) | O_NONBLOCK) == -1) {
lprintf("mms: failed to set socket flags: %s\n", strerror(errno));
return -1;
}
@@ -218,8 +218,31 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port)
sin.sin_addr = ia;
sin.sin_port = htons(port);
- if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) ==-1 && errno != EINPROGRESS) {
- continue;
+ time_t t = time (NULL);
+ int error = 0;
+ for (;;) {
+ int res = connect(s, (struct sockaddr *)&sin, sizeof(sin));
+ if (res == -1 && (errno == EINPROGRESS || errno == EALREADY)) {
+ if (time (NULL) - t > 3) {
+ error = -1;
+ break;
+ }
+ sleep(1);
+ continue;
+ }
+ else if (res == -1 && errno == EISCONN) {
+ break;
+ }
+ else if (res == -1) {
+ error = -1;
+ break;
+ }
+ }
+// if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) ==-1 && errno != EINPROGRESS) {
+// continue;
+// }
+ if (error) {
+ continue;
}
return s;