added unix socket support into httpd urs
This commit is contained in:
parent
79ba0215eb
commit
718fd13481
@ -189,6 +189,12 @@ static qse_sck_hnd_t open_server_socket (int proto, const qse_nwad_t* bindnwad)
|
|||||||
type = SOCK_DGRAM;
|
type = SOCK_DGRAM;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (bindnwad->type == QSE_NWAD_LOCAL)
|
||||||
|
{
|
||||||
|
proto = 0;
|
||||||
|
/* TODO: delete sun_path */
|
||||||
|
}
|
||||||
|
|
||||||
s = socket (family, type, proto);
|
s = socket (family, type, proto);
|
||||||
if (!qse_isvalidsckhnd(s))
|
if (!qse_isvalidsckhnd(s))
|
||||||
{
|
{
|
||||||
|
@ -107,6 +107,9 @@ struct qse_skad_t
|
|||||||
#endif
|
#endif
|
||||||
/* TODO: is this large enough?? */
|
/* TODO: is this large enough?? */
|
||||||
qse_uint8_t data[QSE_SKAD_DATA_SIZE];
|
qse_uint8_t data[QSE_SKAD_DATA_SIZE];
|
||||||
|
|
||||||
|
/* dummy member to secure extra space and force structure alignment */
|
||||||
|
qse_uintptr_t dummy;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -133,23 +133,47 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
|
|||||||
#if defined(AF_INET6)
|
#if defined(AF_INET6)
|
||||||
urs->handle[1] = open_udp_socket (httpd, AF_INET6, type, proto);
|
urs->handle[1] = open_udp_socket (httpd, AF_INET6, type, proto);
|
||||||
#endif
|
#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;
|
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 */
|
/* carry on regardless of success or failure */
|
||||||
dc->skadlen = qse_nwadtoskad (&nwad, &dc->skad);
|
dc->skadlen = qse_nwadtoskad (&nwad, &dc->skad);
|
||||||
|
|
||||||
/* determine which socket to use when sending a request to the server */
|
/* determine which socket to use when sending a request to the server */
|
||||||
if (dc->skadlen >= 0)
|
if (dc->skadlen >= 0)
|
||||||
{
|
{
|
||||||
if (nwad.type == QSE_NWAD_IN4)
|
switch (nwad.type)
|
||||||
dc->urs_socket = urs->handle[0];
|
{
|
||||||
else
|
case QSE_NWAD_IN4:
|
||||||
dc->urs_socket = urs->handle[1];
|
dc->urs_socket = urs->handle[0];
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -414,10 +438,20 @@ printf ("... URS_SEND.....................\n");
|
|||||||
req->urs_skadlen = qse_nwadtoskad (&urs_server->nwad, &req->urs_skad);
|
req->urs_skadlen = qse_nwadtoskad (&urs_server->nwad, &req->urs_skad);
|
||||||
if (req->urs_skadlen <= -1) goto default_urs_server;
|
if (req->urs_skadlen <= -1) goto default_urs_server;
|
||||||
|
|
||||||
if (urs_server->nwad.type == QSE_NWAD_IN4)
|
switch (urs_server->nwad.type)
|
||||||
req->urs_socket = urs->handle[0];
|
{
|
||||||
else
|
case QSE_NWAD_IN4:
|
||||||
req->urs_socket = urs->handle[1];
|
req->urs_socket = urs->handle[0];
|
||||||
|
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
|
else
|
||||||
{
|
{
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
# include "../cmn/syscall.h"
|
# include "../cmn/syscall.h"
|
||||||
# include <sys/socket.h>
|
# include <sys/socket.h>
|
||||||
# include <netinet/in.h>
|
# include <netinet/in.h>
|
||||||
|
# include <sys/un.h>
|
||||||
# if defined(HAVE_SYS_SENDFILE_H)
|
# if defined(HAVE_SYS_SENDFILE_H)
|
||||||
# include <sys/sendfile.h>
|
# include <sys/sendfile.h>
|
||||||
# endif
|
# endif
|
||||||
@ -846,10 +847,9 @@ static int server_open (qse_httpd_t* httpd, qse_httpd_server_t* server)
|
|||||||
{
|
{
|
||||||
/* TODO: logging. warning only */
|
/* TODO: logging. warning only */
|
||||||
/* this is not a hard failure */
|
/* 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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* TODO: linux. use capset() to set required capabilities just in case */
|
/* TODO: linux. use capset() to set required capabilities just in case */
|
||||||
|
@ -957,7 +957,7 @@ static int activate_urs (qse_httpd_t* httpd)
|
|||||||
|
|
||||||
httpd->urs.type = QSE_HTTPD_URS;
|
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))
|
if (httpd->urs.handle_mask & (1 << i))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user