summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pttbbs/common/sys/net.c16
-rw-r--r--pttbbs/include/cmsys.h1
2 files changed, 13 insertions, 4 deletions
diff --git a/pttbbs/common/sys/net.c b/pttbbs/common/sys/net.c
index fff804ec..143f4fd9 100644
--- a/pttbbs/common/sys/net.c
+++ b/pttbbs/common/sys/net.c
@@ -140,6 +140,11 @@ int toconnect(const char *addr)
int toconnectex(const char *addr, int timeout)
{
+ return toconnect3(addr, timeout, 0);
+}
+
+int toconnect3(const char *addr, int timeout, int microseconds)
+{
int sock;
assert(addr && *addr);
@@ -164,13 +169,14 @@ int toconnectex(const char *addr, int timeout)
char buf[64], *port;
struct sockaddr_in serv_name;
int was_block = 1;
+ int timed = timeout > 0 || (timeout == 0 && microseconds > 0);
if( (sock = socket(PF_INET, SOCK_STREAM, 0)) < 0 ){
perror("socket");
return -1;
}
- if (timeout > 0)
+ if (timed)
{
// set to non-block to allow timeout
int oflags = fcntl(sock, F_GETFL, NULL);
@@ -199,8 +205,10 @@ int toconnectex(const char *addr, int timeout)
struct timeval tv = {0};
fd_set myset;
- assert(timeout > 0);
- tv.tv_sec = timeout; // set timeout here
+ assert(timed);
+ // set timeout here
+ tv.tv_sec = timeout;
+ tv.tv_usec = microseconds;
FD_ZERO(&myset);
FD_SET(sock, &myset);
@@ -220,7 +228,7 @@ int toconnectex(const char *addr, int timeout)
return -1;
}
- if (timeout > 0)
+ if (timed)
{
// restore flags
int oflags = fcntl(sock, F_GETFL, NULL);
diff --git a/pttbbs/include/cmsys.h b/pttbbs/include/cmsys.h
index 9b929f0f..8c0bf5e8 100644
--- a/pttbbs/include/cmsys.h
+++ b/pttbbs/include/cmsys.h
@@ -82,6 +82,7 @@ int tobind (const char *addr);
int tobindex (const char *addr, int qlen, int (*setsock)(int), int do_listen);
int toconnect(const char *addr);
int toconnectex(const char *addr, int timeout);
+int toconnect3(const char *addr, int timeout, int microseconds);
int toread (int fd, void *buf, int len);
int towrite (int fd, const void *buf, int len);
int torecv (int fd, void *buf, int len, int flag);