added unix socket support into httpd urs

This commit is contained in:
hyung-hwan 2014-09-26 16:46:10 +00:00
parent 79ba0215eb
commit 718fd13481
5 changed files with 56 additions and 13 deletions

View File

@ -189,6 +189,12 @@ static qse_sck_hnd_t open_server_socket (int proto, const qse_nwad_t* bindnwad)
type = SOCK_DGRAM;
#endif
if (bindnwad->type == QSE_NWAD_LOCAL)
{
proto = 0;
/* TODO: delete sun_path */
}
s = socket (family, type, proto);
if (!qse_isvalidsckhnd(s))
{

View File

@ -107,6 +107,9 @@ struct qse_skad_t
#endif
/* TODO: is this large enough?? */
qse_uint8_t data[QSE_SKAD_DATA_SIZE];
/* dummy member to secure extra space and force structure alignment */
qse_uintptr_t dummy;
};
#ifdef __cplusplus

View File

@ -133,23 +133,47 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
#if defined(AF_INET6)
urs->handle[1] = open_udp_socket (httpd, AF_INET6, type, proto);
#endif
/*urs->handle[2] = open_unix_socket (httpd, AF_UNIX, SOCK_DGRAM);*/
urs->handle[2] = open_udp_socket (httpd, AF_UNIX, type, 0);
if (!qse_isvalidsckhnd(urs->handle[0]) && !qse_isvalidsckhnd(urs->handle[1]))
if (!qse_isvalidsckhnd(urs->handle[0]) &&
!qse_isvalidsckhnd(urs->handle[1]) &&
!qse_isvalidsckhnd(urs->handle[2]))
{
goto oops;
}
if (qse_isvalidsckhnd(urs->handle[2]))
{
struct sockaddr_un addr;
QSE_MEMSET (&addr, 0, QSE_SIZEOF(addr));
addr.sun_family = AF_UNIX;
qse_mbsxfmt (addr.sun_path, QSE_COUNTOF(addr.sun_path), QSE_MT("/tmp/qsehttpd-%d.urs.sock"), (int)QSE_GETPID());
QSE_UNLINK (addr.sun_path);
bind (urs->handle[2], (struct sockaddr*)&addr, QSE_SIZEOF(addr));
/* TOOD: unlink this socket in urs_close() also... */
}
/* carry on regardless of success or failure */
dc->skadlen = qse_nwadtoskad (&nwad, &dc->skad);
/* determine which socket to use when sending a request to the server */
if (dc->skadlen >= 0)
{
if (nwad.type == QSE_NWAD_IN4)
switch (nwad.type)
{
case QSE_NWAD_IN4:
dc->urs_socket = urs->handle[0];
else
break;
case QSE_NWAD_IN6:
dc->urs_socket = urs->handle[1];
break;
case QSE_NWAD_LOCAL:
dc->urs_socket = urs->handle[2];
break;
default:
dc->urs_socket = QSE_INVALID_SCKHND;
break;
}
}
else
{
@ -414,10 +438,20 @@ printf ("... URS_SEND.....................\n");
req->urs_skadlen = qse_nwadtoskad (&urs_server->nwad, &req->urs_skad);
if (req->urs_skadlen <= -1) goto default_urs_server;
if (urs_server->nwad.type == QSE_NWAD_IN4)
switch (urs_server->nwad.type)
{
case QSE_NWAD_IN4:
req->urs_socket = urs->handle[0];
else
break;
case QSE_NWAD_IN6:
req->urs_socket = urs->handle[1];
break;
case QSE_NWAD_LOCAL:
req->urs_socket = urs->handle[2];
break;
default:
goto default_urs_server;
}
}
else
{

View File

@ -74,6 +74,7 @@
# include "../cmn/syscall.h"
# include <sys/socket.h>
# include <netinet/in.h>
# include <sys/un.h>
# if defined(HAVE_SYS_SENDFILE_H)
# include <sys/sendfile.h>
# endif
@ -846,12 +847,11 @@ static int server_open (qse_httpd_t* httpd, qse_httpd_server_t* server)
{
/* TODO: logging. warning only */
/* this is not a hard failure */
qse_printf (QSE_STDERR, QSE_T("Failed to enable SO_REUSEPORT\n"));
qse_fprintf (QSE_STDERR, QSE_T("Failed to enable SO_REUSEPORT\n"));
}
#endif
/* TODO: linux. use capset() to set required capabilities just in case */
#if defined(IP_TRANSPARENT)
/* remove the ip routing restriction that a packet can only

View File

@ -957,7 +957,7 @@ static int activate_urs (qse_httpd_t* httpd)
httpd->urs.type = QSE_HTTPD_URS;
for (i = 0; i < httpd->dns.handle_count; i++)
for (i = 0; i < httpd->urs.handle_count; i++)
{
if (httpd->urs.handle_mask & (1 << i))
{