Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
e6d997a9
Commit
e6d997a9
authored
Jun 27, 2011
by
Pieter Noordhuis
Browse files
Extract function to check a socket for errors
parent
026d5ae7
Changes
2
Hide whitespace changes
Inline
Side-by-side
net.c
View file @
e6d997a9
...
@@ -117,8 +117,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
...
@@ -117,8 +117,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
struct
timeval
to
;
struct
timeval
to
;
struct
timeval
*
toptr
=
NULL
;
struct
timeval
*
toptr
=
NULL
;
fd_set
wfd
;
fd_set
wfd
;
int
err
;
socklen_t
errlen
;
/* Only use timeout when not NULL. */
/* Only use timeout when not NULL. */
if
(
timeout
!=
NULL
)
{
if
(
timeout
!=
NULL
)
{
...
@@ -143,21 +141,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
...
@@ -143,21 +141,6 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
err
=
0
;
errlen
=
sizeof
(
err
);
if
(
getsockopt
(
fd
,
SOL_SOCKET
,
SO_ERROR
,
&
err
,
&
errlen
)
==
-
1
)
{
__redisSetErrorFromErrno
(
c
,
REDIS_ERR_IO
,
"getsockopt(SO_ERROR)"
);
close
(
fd
);
return
REDIS_ERR
;
}
if
(
err
)
{
errno
=
err
;
__redisSetErrorFromErrno
(
c
,
REDIS_ERR_IO
,
NULL
);
close
(
fd
);
return
REDIS_ERR
;
}
return
REDIS_OK
;
return
REDIS_OK
;
}
}
...
@@ -166,6 +149,26 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
...
@@ -166,6 +149,26 @@ static int redisContextWaitReady(redisContext *c, int fd, const struct timeval *
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
int
redisCheckSocketError
(
redisContext
*
c
,
int
fd
)
{
int
err
=
0
;
socklen_t
errlen
=
sizeof
(
err
);
if
(
getsockopt
(
fd
,
SOL_SOCKET
,
SO_ERROR
,
&
err
,
&
errlen
)
==
-
1
)
{
__redisSetErrorFromErrno
(
c
,
REDIS_ERR_IO
,
"getsockopt(SO_ERROR)"
);
close
(
fd
);
return
REDIS_ERR
;
}
if
(
err
)
{
errno
=
err
;
__redisSetErrorFromErrno
(
c
,
REDIS_ERR_IO
,
NULL
);
close
(
fd
);
return
REDIS_ERR
;
}
return
REDIS_OK
;
}
int
redisContextSetTimeout
(
redisContext
*
c
,
struct
timeval
tv
)
{
int
redisContextSetTimeout
(
redisContext
*
c
,
struct
timeval
tv
)
{
if
(
setsockopt
(
c
->
fd
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
tv
,
sizeof
(
tv
))
==
-
1
)
{
if
(
setsockopt
(
c
->
fd
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
tv
,
sizeof
(
tv
))
==
-
1
)
{
__redisSetErrorFromErrno
(
c
,
REDIS_ERR_IO
,
"setsockopt(SO_RCVTIMEO)"
);
__redisSetErrorFromErrno
(
c
,
REDIS_ERR_IO
,
"setsockopt(SO_RCVTIMEO)"
);
...
...
net.h
View file @
e6d997a9
...
@@ -39,6 +39,7 @@
...
@@ -39,6 +39,7 @@
#define AF_LOCAL AF_UNIX
#define AF_LOCAL AF_UNIX
#endif
#endif
int
redisCheckSocketError
(
redisContext
*
c
,
int
fd
);
int
redisContextSetTimeout
(
redisContext
*
c
,
struct
timeval
tv
);
int
redisContextSetTimeout
(
redisContext
*
c
,
struct
timeval
tv
);
int
redisContextConnectTcp
(
redisContext
*
c
,
const
char
*
addr
,
int
port
,
struct
timeval
*
timeout
);
int
redisContextConnectTcp
(
redisContext
*
c
,
const
char
*
addr
,
int
port
,
struct
timeval
*
timeout
);
int
redisContextConnectUnix
(
redisContext
*
c
,
const
char
*
path
,
struct
timeval
*
timeout
);
int
redisContextConnectUnix
(
redisContext
*
c
,
const
char
*
path
,
struct
timeval
*
timeout
);
...
...
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