mirror of
https://github.com/nmap/nmap.git
synced 2025-12-17 21:19:01 +00:00
Merged nsock-engines from nmap-exp. This rewrite of the nsock library adds
support for system-specific scalable IO notification facilities without breaking portability. This initial version comes with an epoll(7)-based engine for Linux and a select(2)-based fallback engine for all other operating systems. This required an important refactoring of the library but the external API was preserved. The rewrite also tries to bring the coding standards of nmap to nsock. See http://labs.unix-junkies.org/nsock_engines.html for the details.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
/***************************************************************************
|
||||
* nsock_read.c -- This contains the functions for requesting various read *
|
||||
* events from the nsock parallel socket event library *
|
||||
@@ -58,48 +57,43 @@
|
||||
|
||||
#include "nsock_internal.h"
|
||||
|
||||
/* Read up to nlines lines (terminated with \n, which of course
|
||||
inclues \r\n), or until EOF, or until the timeout, whichever comes
|
||||
first. Note that NSE_STATUS_SUCCESS will be returned in the case
|
||||
of EOF or tiemout if at least 1 char has been read. Also note that
|
||||
you may get more than 'nlines' back -- we just stop once "at least"
|
||||
'nlines' is read */
|
||||
nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, int nlines) {
|
||||
msiod *nsi = (msiod *) ms_iod;
|
||||
mspool *ms = (mspool *) nsp;
|
||||
msevent *nse;
|
||||
|
||||
/* Read up to nlines lines (terminated with \n, which of course inclues \r\n),
|
||||
* or until EOF, or until the timeout, whichever comes first. Note that
|
||||
* NSE_STATUS_SUCCESS will be returned in the case of EOF or tiemout if at least
|
||||
* 1 char has been read. Also note that you may get more than 'nlines' back --
|
||||
* we just stop once "at least" 'nlines' is read */
|
||||
nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, int nlines) {
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
if (ms->tracelevel > 0) {
|
||||
if (nsi->peerlen > 0)
|
||||
nsock_trace(ms, "Read request for %d lines from IOD #%li [%s:%hu] EID %li", nlines, nsi->id,
|
||||
inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), nse->id);
|
||||
else
|
||||
nsock_trace(ms, "Read request for %d lines from IOD #%li (peer unspecified) EID %li", nlines,
|
||||
nsi->id, nse->id);
|
||||
nsock_trace(ms, "Read request for %d lines from IOD #%li [%s:%d] EID %li", nlines, nsi->id,
|
||||
inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), nse->id);
|
||||
else
|
||||
nsock_trace(ms, "Read request for %d lines from IOD #%li (peer unspecified) EID %li", nlines, nsi->id, nse->id);
|
||||
}
|
||||
|
||||
|
||||
nse->readinfo.read_type = NSOCK_READLINES;
|
||||
nse->readinfo.num = nlines;
|
||||
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
/* Same as above, except it tries to read at least 'nbytes' instead of
|
||||
'nlines'. */
|
||||
nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, int nbytes) {
|
||||
/* Same as above, except it tries to read at least 'nbytes' instead of 'nlines'. */
|
||||
nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, int nbytes) {
|
||||
|
||||
msiod *nsi = (msiod *) ms_iod;
|
||||
mspool *ms = (mspool *) nsp;
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
@@ -107,31 +101,26 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod,
|
||||
|
||||
if (ms->tracelevel > 0) {
|
||||
if (nsi->peerlen > 0)
|
||||
nsock_trace(ms, "Read request for %d bytes from IOD #%li [%s:%hu] EID %li", nbytes, nsi->id,
|
||||
inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), nse->id);
|
||||
else
|
||||
nsock_trace(ms, "Read request for %d bytes from IOD #%li (peer unspecified) EID %li", nbytes,
|
||||
nsi->id, nse->id);
|
||||
nsock_trace(ms, "Read request for %d bytes from IOD #%li [%s:%d] EID %li", nbytes, nsi->id,
|
||||
inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), nse->id);
|
||||
else
|
||||
nsock_trace(ms, "Read request for %d bytes from IOD #%li (peer unspecified) EID %li", nbytes, nsi->id, nse->id);
|
||||
}
|
||||
|
||||
nse->readinfo.read_type = NSOCK_READBYTES;
|
||||
nse->readinfo.num = nbytes;
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
|
||||
/* The simplest read function -- returns NSE_STATUS_SUCCESS when it
|
||||
reads anything, otherwise it returns timeout, eof, or error as
|
||||
appropriate */
|
||||
nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler,
|
||||
int timeout_msecs, void *userdata) {
|
||||
|
||||
msiod *nsi = (msiod *) ms_iod;
|
||||
mspool *ms = (mspool *) nsp;
|
||||
* reads anything, otherwise it returns timeout, eof, or error as appropriate */
|
||||
nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs, void *userdata) {
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
@@ -139,16 +128,17 @@ nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler han
|
||||
|
||||
if (ms->tracelevel > 0) {
|
||||
if (nsi->peerlen > 0)
|
||||
nsock_trace(ms, "Read request from IOD #%li [%s:%hu] (timeout: %dms) EID %li", nsi->id, inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), timeout_msecs, nse->id);
|
||||
else
|
||||
nsock_trace(ms, "Read request from IOD #%li (peer unspecified) (timeout: %dms) EID %li", nsi->id, timeout_msecs, nse->id);
|
||||
nsock_trace(ms, "Read request from IOD #%li [%s:%d] (timeout: %dms) EID %li", nsi->id,
|
||||
inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), timeout_msecs, nse->id);
|
||||
else
|
||||
nsock_trace(ms, "Read request from IOD #%li (peer unspecified) (timeout: %dms) EID %li",
|
||||
nsi->id, timeout_msecs, nse->id);
|
||||
}
|
||||
|
||||
nse->readinfo.read_type = NSOCK_READ;
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
|
||||
nsp_add_event(ms, nse);
|
||||
|
||||
return nse->id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user