unix: add support for receiving UNIX sockets
Until now, all received file descriptors were reported as being UV_TCP streams: AF_INET/AF_INET6 sockets of type SOCK_STREAM. This commit adds support for AF_UNIX/AF_FILE sockets (UV_NAMED_PIPE in libuv nomenclature). Support for UV_UDP handles (AF_INET/AF_INET6 sockets of type SOCK_DGRAM) still needs to be implemented.
This commit is contained in:
parent
8ffad48818
commit
71eea07a95
@ -22,14 +22,17 @@
|
||||
#include "uv.h"
|
||||
#include "internal.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/uio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
static void uv__stream_connect(uv_stream_t*);
|
||||
@ -513,6 +516,28 @@ static void uv__write_callbacks(uv_stream_t* stream) {
|
||||
}
|
||||
|
||||
|
||||
static uv_handle_type uv__handle_type(int fd) {
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t len;
|
||||
|
||||
memset(&ss, 0, sizeof(ss));
|
||||
len = sizeof(ss);
|
||||
|
||||
if (getsockname(fd, (struct sockaddr*)&ss, &len))
|
||||
return UV_UNKNOWN_HANDLE;
|
||||
|
||||
switch (ss.ss_family) {
|
||||
case AF_UNIX:
|
||||
return UV_NAMED_PIPE;
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
return UV_TCP;
|
||||
}
|
||||
|
||||
return UV_UNKNOWN_HANDLE;
|
||||
}
|
||||
|
||||
|
||||
static void uv__read(uv_stream_t* stream) {
|
||||
uv_buf_t buf;
|
||||
ssize_t nread;
|
||||
@ -633,7 +658,8 @@ static void uv__read(uv_stream_t* stream) {
|
||||
|
||||
|
||||
if (stream->accepted_fd >= 0) {
|
||||
stream->read2_cb((uv_pipe_t*)stream, nread, buf, UV_TCP);
|
||||
stream->read2_cb((uv_pipe_t*)stream, nread, buf,
|
||||
uv__handle_type(stream->accepted_fd));
|
||||
} else {
|
||||
stream->read2_cb((uv_pipe_t*)stream, nread, buf, UV_UNKNOWN_HANDLE);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user