fixed a minor bug in mux.c
improved dns and urs handling for QSE_NWAD_LOCAL
This commit is contained in:
parent
a003346acf
commit
117b1d3618
@ -99,7 +99,10 @@ struct qse_mux_t
|
||||
|
||||
int kq;
|
||||
|
||||
/* event list: TODO: find the optimal size or make it auto-scalable */
|
||||
/* kevent() places the events into the event list up to the limit specified.
|
||||
* this implementation passes the 'evlist' array to kevent() upon polling.
|
||||
* what is the best array size?
|
||||
* TODO: find the optimal size or make it auto-scalable. */
|
||||
struct kevent evlist[512];
|
||||
int size;
|
||||
struct
|
||||
@ -708,7 +711,7 @@ int qse_mux_delete (qse_mux_t* mux, const qse_mux_evt_t* evt)
|
||||
}
|
||||
|
||||
mevt = mux->me.ptr[evt->hnd];
|
||||
if (mevt->hnd != evt->hnd)
|
||||
if (!mevt || mevt->hnd != evt->hnd)
|
||||
{
|
||||
/* already deleted??? */
|
||||
mux->errnum = QSE_MUX_EINVAL;
|
||||
@ -756,7 +759,7 @@ done:
|
||||
}
|
||||
|
||||
mevt = mux->me.ptr[evt->hnd];
|
||||
if (mevt->hnd != evt->hnd)
|
||||
if (!mevt || mevt->hnd != evt->hnd)
|
||||
{
|
||||
/* already deleted??? */
|
||||
mux->errnum = QSE_MUX_EINVAL;
|
||||
@ -814,7 +817,7 @@ done:
|
||||
}
|
||||
|
||||
mevt = mux->me.ptr[evt->hnd];
|
||||
if (mevt->hnd != evt->hnd)
|
||||
if (!mevt || mevt->hnd != evt->hnd)
|
||||
{
|
||||
/* already deleted??? */
|
||||
mux->errnum = QSE_MUX_EINVAL;
|
||||
@ -889,8 +892,7 @@ int qse_mux_poll (qse_mux_t* mux, const qse_ntime_t* tmout)
|
||||
ts.tv_nsec = tmout->nsec;
|
||||
|
||||
/* wait for events */
|
||||
nevs = kevent (mux->kq, QSE_NULL, 0,
|
||||
mux->evlist, QSE_COUNTOF(mux->evlist), &ts);
|
||||
nevs = kevent (mux->kq, QSE_NULL, 0, mux->evlist, QSE_COUNTOF(mux->evlist), &ts);
|
||||
if (nevs <= -1)
|
||||
{
|
||||
mux->errnum = skerr_to_errnum(errno);
|
||||
|
@ -366,19 +366,32 @@ static int dns_open (qse_httpd_t* httpd, qse_httpd_dns_t* dns)
|
||||
#endif
|
||||
if (!qse_isvalidsckhnd(dns->handle[0]) && !qse_isvalidsckhnd(dns->handle[1]))
|
||||
{
|
||||
/* don't set the error number here.
|
||||
* open_udp_socket() should set it */
|
||||
goto oops;
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
/* determine which socket to use when sending a request to the default server */
|
||||
if (dc->skadlen >= 0)
|
||||
{
|
||||
if (nwad.type == QSE_NWAD_IN4)
|
||||
switch (nwad.type)
|
||||
{
|
||||
case QSE_NWAD_IN4:
|
||||
dc->dns_socket = dns->handle[0];
|
||||
else
|
||||
break;
|
||||
|
||||
case QSE_NWAD_IN6:
|
||||
dc->dns_socket = dns->handle[1];
|
||||
break;
|
||||
|
||||
default:
|
||||
/* unsupported address type for the default server */
|
||||
dc->dns_socket = QSE_INVALID_SCKHND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -870,10 +883,18 @@ printf ("DNS REALLY SENING>>>>>>>>>>>>>>>>>>>>>>>\n");
|
||||
req->dns_skadlen = qse_nwadtoskad (&dns_server->nwad, &req->dns_skad);
|
||||
if (req->dns_skadlen <= -1) goto default_dns_server;
|
||||
|
||||
if (dns_server->nwad.type == QSE_NWAD_IN4)
|
||||
switch (dns_server->nwad.type)
|
||||
{
|
||||
case QSE_NWAD_IN4:
|
||||
req->dns_socket = dns->handle[0];
|
||||
else
|
||||
break;
|
||||
case QSE_NWAD_IN6:
|
||||
req->dns_socket = dns->handle[1];
|
||||
break;
|
||||
default:
|
||||
qse_httpd_seterrnum (httpd, QSE_HTTPD_EINVAL);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
dns_flags = dns_server->flags;
|
||||
}
|
||||
|
@ -151,15 +151,15 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
|
||||
QSE_MEMSET (&dc->unix_bind_addr, 0, QSE_SIZEOF(dc->unix_bind_addr));
|
||||
dc->unix_bind_addr.sun_family = AF_UNIX;
|
||||
/* TODO: safer way to bind. what if the file name collides? */
|
||||
|
||||
qse_mbsxfmt (
|
||||
dc->unix_bind_addr.sun_path,
|
||||
QSE_COUNTOF(dc->unix_bind_addr.sun_path),
|
||||
QSE_MT("/tmp/.urs-%d-%ld-%ld"),
|
||||
(int)QSE_GETPID(), (long int)now.sec, (long int)now.nsec
|
||||
);
|
||||
QSE_MT("/tmp/.urs-%x-%zx"), (int)QSE_GETPID(), (qse_size_t)dc);
|
||||
QSE_UNLINK (dc->unix_bind_addr.sun_path);
|
||||
if (bind (urs->handle[2], (struct sockaddr*)&dc->unix_bind_addr, QSE_SIZEOF(dc->unix_bind_addr)) <= -1)
|
||||
{
|
||||
qse_httpd_seterrnum (httpd, SKERR_TO_ERRNUM());
|
||||
qse_closesckhnd (urs->handle[2]);
|
||||
urs->handle[2] = QSE_INVALID_SCKHND;
|
||||
}
|
||||
@ -170,6 +170,8 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
|
||||
!qse_isvalidsckhnd(urs->handle[1]) &&
|
||||
!qse_isvalidsckhnd(urs->handle[2]))
|
||||
{
|
||||
/* don't set the error number here.
|
||||
* open_udp_socket() or bind() above should set the error number */
|
||||
goto oops;
|
||||
}
|
||||
|
||||
@ -191,6 +193,7 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
|
||||
dc->urs_socket = urs->handle[2];
|
||||
break;
|
||||
default:
|
||||
/* unsupported address for the default server */
|
||||
dc->urs_socket = QSE_INVALID_SCKHND;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user