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
hiredis
Commits
0ccb2c8d
Commit
0ccb2c8d
authored
Nov 03, 2010
by
Pieter Noordhuis
Browse files
Add functiont to net.c to connect to a unix socket
parent
8220cd4b
Changes
3
Hide whitespace changes
Inline
Side-by-side
hiredis.c
View file @
0ccb2c8d
...
...
@@ -655,7 +655,7 @@ redisContext *redisConnect(const char *ip, int port) {
redisContext
*
c
=
redisContextInit
();
c
->
flags
|=
REDIS_BLOCK
;
c
->
flags
|=
REDIS_CONNECTED
;
redisContextConnect
(
c
,
ip
,
port
);
redisContextConnect
Tcp
(
c
,
ip
,
port
);
return
c
;
}
...
...
@@ -663,7 +663,7 @@ redisContext *redisConnectNonBlock(const char *ip, int port) {
redisContext
*
c
=
redisContextInit
();
c
->
flags
&=
~
REDIS_BLOCK
;
c
->
flags
|=
REDIS_CONNECTED
;
redisContextConnect
(
c
,
ip
,
port
);
redisContextConnect
Tcp
(
c
,
ip
,
port
);
return
c
;
}
...
...
net.c
View file @
0ccb2c8d
...
...
@@ -31,6 +31,7 @@
#include "fmacros.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
...
...
@@ -95,7 +96,7 @@ static int redisSetTcpNoDelay(redisContext *c, int fd) {
return
REDIS_OK
;
}
int
redisContextConnect
(
redisContext
*
c
,
const
char
*
addr
,
int
port
)
{
int
redisContextConnect
Tcp
(
redisContext
*
c
,
const
char
*
addr
,
int
port
)
{
int
s
;
int
blocking
=
(
c
->
flags
&
REDIS_BLOCK
);
struct
sockaddr_in
sa
;
...
...
@@ -138,3 +139,29 @@ int redisContextConnect(redisContext *c, const char *addr, int port) {
c
->
fd
=
s
;
return
REDIS_OK
;
}
int
redisContextConnectUnix
(
redisContext
*
c
,
const
char
*
path
)
{
int
s
;
int
blocking
=
(
c
->
flags
&
REDIS_BLOCK
);
struct
sockaddr_un
sa
;
if
((
s
=
redisCreateSocket
(
c
,
AF_LOCAL
))
==
REDIS_ERR
)
return
REDIS_ERR
;
if
(
!
blocking
&&
redisSetNonBlock
(
c
,
s
)
!=
REDIS_OK
)
return
REDIS_ERR
;
sa
.
sun_family
=
AF_LOCAL
;
strncpy
(
sa
.
sun_path
,
path
,
sizeof
(
sa
.
sun_path
)
-
1
);
if
(
connect
(
s
,
(
struct
sockaddr
*
)
&
sa
,
sizeof
(
sa
))
==
-
1
)
{
if
(
errno
==
EINPROGRESS
&&
!
blocking
)
{
/* This is ok. */
}
else
{
__redisSetError
(
c
,
REDIS_ERR_IO
,
NULL
);
close
(
s
);
return
REDIS_ERR
;
}
}
c
->
fd
=
s
;
return
REDIS_OK
;
}
net.h
View file @
0ccb2c8d
...
...
@@ -31,6 +31,7 @@
#ifndef __NET_H
#define __NET_H
int
redisContextConnect
(
redisContext
*
c
,
const
char
*
addr
,
int
port
);
int
redisContextConnectTcp
(
redisContext
*
c
,
const
char
*
addr
,
int
port
);
int
redisContextConnectUnix
(
redisContext
*
c
,
const
char
*
path
);
#endif
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