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
74f90c61
Commit
74f90c61
authored
Oct 17, 2014
by
antirez
Browse files
anet.c: API to set sockets back to blocking mode.
parent
10aafdad
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/anet.c
View file @
74f90c61
...
@@ -57,24 +57,37 @@ static void anetSetError(char *err, const char *fmt, ...)
...
@@ -57,24 +57,37 @@ static void anetSetError(char *err, const char *fmt, ...)
va_end
(
ap
);
va_end
(
ap
);
}
}
int
anetNonBlock
(
char
*
err
,
int
fd
)
int
anetSetBlock
(
char
*
err
,
int
fd
,
int
non_block
)
{
{
int
flags
;
int
flags
;
/* Set the socket non-blocking.
/* Set the socket
blocking (if non_block is zero) or
non-blocking.
* Note that fcntl(2) for F_GETFL and F_SETFL can't be
* Note that fcntl(2) for F_GETFL and F_SETFL can't be
* interrupted by a signal. */
* interrupted by a signal. */
if
((
flags
=
fcntl
(
fd
,
F_GETFL
))
==
-
1
)
{
if
((
flags
=
fcntl
(
fd
,
F_GETFL
))
==
-
1
)
{
anetSetError
(
err
,
"fcntl(F_GETFL): %s"
,
strerror
(
errno
));
anetSetError
(
err
,
"fcntl(F_GETFL): %s"
,
strerror
(
errno
));
return
ANET_ERR
;
return
ANET_ERR
;
}
}
if
(
fcntl
(
fd
,
F_SETFL
,
flags
|
O_NONBLOCK
)
==
-
1
)
{
if
(
non_block
)
flags
|=
O_NONBLOCK
;
else
flags
&=
~
O_NONBLOCK
;
if
(
fcntl
(
fd
,
F_SETFL
,
flags
)
==
-
1
)
{
anetSetError
(
err
,
"fcntl(F_SETFL,O_NONBLOCK): %s"
,
strerror
(
errno
));
anetSetError
(
err
,
"fcntl(F_SETFL,O_NONBLOCK): %s"
,
strerror
(
errno
));
return
ANET_ERR
;
return
ANET_ERR
;
}
}
return
ANET_OK
;
return
ANET_OK
;
}
}
int
anetNonBlock
(
char
*
err
,
int
fd
)
{
return
anetSetBlock
(
err
,
fd
,
1
);
}
int
anetBlock
(
char
*
err
,
int
fd
)
{
return
anetSetBlock
(
err
,
fd
,
0
);
}
/* Set TCP keep alive option to detect dead peers. The interval option
/* Set TCP keep alive option to detect dead peers. The interval option
* is only used for Linux as we are using Linux-specific APIs to set
* is only used for Linux as we are using Linux-specific APIs to set
* the probe send time, interval, and count. */
* the probe send time, interval, and count. */
...
...
src/anet.h
View file @
74f90c61
...
@@ -62,6 +62,7 @@ int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port)
...
@@ -62,6 +62,7 @@ int anetTcpAccept(char *err, int serversock, char *ip, size_t ip_len, int *port)
int
anetUnixAccept
(
char
*
err
,
int
serversock
);
int
anetUnixAccept
(
char
*
err
,
int
serversock
);
int
anetWrite
(
int
fd
,
char
*
buf
,
int
count
);
int
anetWrite
(
int
fd
,
char
*
buf
,
int
count
);
int
anetNonBlock
(
char
*
err
,
int
fd
);
int
anetNonBlock
(
char
*
err
,
int
fd
);
int
anetBlock
(
char
*
err
,
int
fd
);
int
anetEnableTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetEnableTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetDisableTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetDisableTcpNoDelay
(
char
*
err
,
int
fd
);
int
anetTcpKeepAlive
(
char
*
err
,
int
fd
);
int
anetTcpKeepAlive
(
char
*
err
,
int
fd
);
...
...
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