aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-01 05:26:59 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-01 05:26:59 +0000
commita7d5362caffb928e2947b9ef99d1165391a510da (patch)
tree54e07e3d032c8bd8a6e19b0c7dfc1996437bceaa
parent596602f2caa75dc119fe7071fc74bafdca32bfde (diff)
downloadluasocket-a7d5362caffb928e2947b9ef99d1165391a510da.tar.gz
luasocket-a7d5362caffb928e2947b9ef99d1165391a510da.tar.bz2
luasocket-a7d5362caffb928e2947b9ef99d1165391a510da.zip
Fixed unix domain sockets.
-rw-r--r--src/unix.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/unix.c b/src/unix.c
index b2c4659..34d2da1 100644
--- a/src/unix.c
+++ b/src/unix.c
@@ -153,7 +153,8 @@ static int meth_accept(lua_State *L) {
153 /* initialize structure fields */ 153 /* initialize structure fields */
154 sock_setnonblocking(&sock); 154 sock_setnonblocking(&sock);
155 clnt->sock = sock; 155 clnt->sock = sock;
156 io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv, &clnt->sock); 156 io_init(&clnt->io, (p_send)sock_send, (p_recv)sock_recv,
157 (p_geterr) sock_geterr, &clnt->sock);
157 tm_init(&clnt->tm, -1, -1); 158 tm_init(&clnt->tm, -1, -1);
158 buf_init(&clnt->buf, &clnt->io, &clnt->tm); 159 buf_init(&clnt->buf, &clnt->io, &clnt->tm);
159 return 1; 160 return 1;
@@ -169,14 +170,21 @@ static int meth_accept(lua_State *L) {
169\*-------------------------------------------------------------------------*/ 170\*-------------------------------------------------------------------------*/
170static const char *unix_trybind(p_unix unix, const char *path) { 171static const char *unix_trybind(p_unix unix, const char *path) {
171 struct sockaddr_un local; 172 struct sockaddr_un local;
172 int len = strlen(path); 173 size_t len = strlen(path);
173 const char *err; 174 const char *err;
174 if (len >= 92) return "path too long"; 175 if (len >= sizeof(local.sun_path)) return "path too long";
175 memset(&local, 0, sizeof(local)); 176 memset(&local, 0, sizeof(local));
176 strcpy(local.sun_path, path); 177 strcpy(local.sun_path, path);
177 local.sun_family = AF_UNIX; 178 local.sun_family = AF_UNIX;
179#ifdef UNIX_HAS_SUN_LEN
180 local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len)
181 + len + 1;
182 err = sock_bind(&unix->sock, (SA *) &local, local.sun_len);
183
184#else
178 err = sock_bind(&unix->sock, (SA *) &local, 185 err = sock_bind(&unix->sock, (SA *) &local,
179 sizeof(local.sun_family) + len); 186 sizeof(local.sun_family) + len);
187#endif
180 if (err) sock_destroy(&unix->sock); 188 if (err) sock_destroy(&unix->sock);
181 return err; 189 return err;
182} 190}
@@ -201,14 +209,20 @@ static const char *unix_tryconnect(p_unix unix, const char *path)
201{ 209{
202 struct sockaddr_un remote; 210 struct sockaddr_un remote;
203 const char *err; 211 const char *err;
204 int len = strlen(path); 212 size_t len = strlen(path);
205 if (len >= 92) return "path too long"; 213 if (len >= sizeof(remote.sun_path)) return "path too long";
206 memset(&remote, 0, sizeof(remote)); 214 memset(&remote, 0, sizeof(remote));
207 strcpy(remote.sun_path, path); 215 strcpy(remote.sun_path, path);
208 remote.sun_family = AF_UNIX; 216 remote.sun_family = AF_UNIX;
209 tm_markstart(&unix->tm); 217 tm_markstart(&unix->tm);
218#ifdef UNIX_HAS_SUN_LEN
219 remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len)
220 + len + 1;
221 err = sock_connect(&unix->sock, (SA *) &remote, remote.sun_len, &unix->tm);
222#else
210 err = sock_connect(&unix->sock, (SA *) &remote, 223 err = sock_connect(&unix->sock, (SA *) &remote,
211 sizeof(remote.sun_family) + len, &unix->tm); 224 sizeof(remote.sun_family) + len, &unix->tm);
225#endif
212 if (err) sock_destroy(&unix->sock); 226 if (err) sock_destroy(&unix->sock);
213 return err; 227 return err;
214} 228}
@@ -312,7 +326,8 @@ static int global_create(lua_State *L) {
312 /* initialize remaining structure fields */ 326 /* initialize remaining structure fields */
313 sock_setnonblocking(&sock); 327 sock_setnonblocking(&sock);
314 unix->sock = sock; 328 unix->sock = sock;
315 io_init(&unix->io, (p_send) sock_send, (p_recv) sock_recv, &unix->sock); 329 io_init(&unix->io, (p_send) sock_send, (p_recv) sock_recv,
330 (p_geterr) sock_geterr, &unix->sock);
316 tm_init(&unix->tm, -1, -1); 331 tm_init(&unix->tm, -1, -1);
317 buf_init(&unix->buf, &unix->io, &unix->tm); 332 buf_init(&unix->buf, &unix->io, &unix->tm);
318 return 1; 333 return 1;