Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
2309f15d
Commit
2309f15d
authored
Oct 22, 2014
by
antirez
Browse files
anet.c: new API anetSendTimeout().
parent
456003af
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/anet.c
View file @
2309f15d
...
...
@@ -34,6 +34,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
...
...
@@ -178,6 +179,20 @@ int anetTcpKeepAlive(char *err, int fd)
return
ANET_OK
;
}
/* Set the socket send timeout (SO_SNDTIMEO socket option) to the specified
* number of milliseconds, or disable it if the 'ms' argument is zero. */
int
anetSendTimeout
(
char
*
err
,
int
fd
,
long
long
ms
)
{
struct
timeval
tv
;
tv
.
tv_sec
=
ms
/
1000
;
tv
.
tv_usec
=
(
ms
%
1000
)
*
1000
;
if
(
setsockopt
(
fd
,
SOL_SOCKET
,
SO_SNDTIMEO
,
&
tv
,
sizeof
(
tv
))
==
-
1
)
{
anetSetError
(
err
,
"setsockopt SO_SNDTIMEO: %s"
,
strerror
(
errno
));
return
ANET_ERR
;
}
return
ANET_OK
;
}
/* anetGenericResolve() is called by anetResolve() and anetResolveIP() to
* do the actual work. It resolves the hostname "host" and set the string
* representation of the IP address into the buffer pointed by "ipbuf".
...
...
src/anet.h
View file @
2309f15d
...
...
@@ -66,6 +66,7 @@ int anetBlock(char *err, int fd);
int
anetEnableTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetDisableTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetTcpKeepAlive
(
char
*
err
,
int
fd
);
int
anetSendTimeout
(
char
*
err
,
int
fd
,
long
long
ms
);
int
anetPeerToString
(
int
fd
,
char
*
ip
,
size_t
ip_len
,
int
*
port
);
int
anetKeepAlive
(
char
*
err
,
int
fd
,
int
interval
);
int
anetSockName
(
int
fd
,
char
*
ip
,
size_t
ip_len
,
int
*
port
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment