simple code cleanup in http-file.c
partial code to support select
This commit is contained in:
parent
098bb7b3d6
commit
de5eb613ca
@ -2057,7 +2057,7 @@ void hio_freemem (hio_t* hio, void* ptr)
|
||||
void hio_addcfmb (hio_t* hio, hio_cfmb_t* cfmb, hio_cfmb_checker_t checker, hio_cfmb_freeer_t freeer)
|
||||
{
|
||||
cfmb->cfmb_checker = checker;
|
||||
cfmb->cfmb_freeer = freeer? freeer: hio_freemem;
|
||||
cfmb->cfmb_freeer = freeer? freeer: (hio_cfmb_freeer_t)hio_freemem;
|
||||
HIO_CFMBL_APPEND_CFMB (&hio->cfmb, cfmb);
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,7 @@ static void file_mark_over (file_t* file, int over_bits)
|
||||
{
|
||||
if (file->task_keep_client_alive)
|
||||
{
|
||||
/* TODO: restore to the original value... */
|
||||
set_tcp_cork (file->task_csck, 0);
|
||||
|
||||
/* the file task must not be accessed from here down as it could have been destroyed */
|
||||
@ -226,7 +227,7 @@ static void file_client_on_disconnect (hio_dev_sck_t* sck)
|
||||
unbind_task_from_client (file, 1);
|
||||
|
||||
/* the current file peer implemenation is not async. so there is no IO event associated
|
||||
* when the client side is disconnecte, simple close the peer side as it's not needed.
|
||||
* when the client side is disconnected, simple close the peer side as it's not needed.
|
||||
* this behavior is different from http-fcgi or http-cgi */
|
||||
unbind_task_from_peer (file, 1);
|
||||
|
||||
@ -316,7 +317,7 @@ static int file_client_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wr
|
||||
{
|
||||
if (file->task_req_method == HIO_HTTP_GET)
|
||||
{
|
||||
if (file_send_contents_to_client (file) <= -1) goto oops;
|
||||
if (file_send_contents_to_client (file) <= -1) n = -1;
|
||||
}
|
||||
|
||||
if ((file->over & FILE_OVER_READ_FROM_PEER) && file->task_res_pending_writes <= 0)
|
||||
@ -327,10 +328,6 @@ static int file_client_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wr
|
||||
|
||||
if (n <= -1 || wrlen <= -1) file_halt_participating_devices (file);
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
file_halt_participating_devices (file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
@ -741,6 +738,7 @@ static int bind_task_to_peer (file_t* file, hio_htre_t* req, const hio_bch_t* fi
|
||||
#if defined(HAVE_POSIX_FADVISE)
|
||||
posix_fadvise (file->peer, file->start_offset, file->end_offset - file->start_offset + 1, POSIX_FADV_SEQUENTIAL);
|
||||
#endif
|
||||
/* TODO: store the current value and let the program restore to the current value when exiting.. */
|
||||
set_tcp_cork (file->task_csck, 1);
|
||||
|
||||
if (file_send_header_to_client(file, HIO_HTTP_STATUS_OK, 0, actual_mime_type) <= -1) goto oops;
|
||||
|
@ -22,6 +22,7 @@
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include "sys-prv.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
@ -84,6 +85,9 @@ int hio_sys_initmux (hio_t* hio)
|
||||
mux->pd.dptr[idx] = HIO_NULL;
|
||||
mux->map.ptr[mux->ctrlp[0]] = idx;
|
||||
}
|
||||
#elif defined(USE_SELECT)
|
||||
FD_ZERO (&mux->rfds);
|
||||
FD_ZERO (&mux->wfds);
|
||||
|
||||
#elif defined(USE_KQUEUE)
|
||||
#if defined(HAVE_KQUEUE1) && defined(O_CLOEXEC)
|
||||
@ -188,6 +192,10 @@ void hio_sys_finimux (hio_t* hio)
|
||||
}
|
||||
mux->pd.capa = 0;
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
|
||||
/* nothing to do */
|
||||
|
||||
#elif defined(USE_KQUEUE)
|
||||
if (mux->ctrlp[0] != HIO_SYSHND_INVALID)
|
||||
{
|
||||
@ -409,6 +417,8 @@ int hio_sys_ctrlmux (hio_t* hio, hio_sys_mux_cmd_t cmd, hio_dev_t* dev, int dev_
|
||||
return -1;
|
||||
}
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
|
||||
#elif defined(USE_KQUEUE)
|
||||
|
||||
hio_sys_mux_t* mux = &hio->sysdep->mux;
|
||||
@ -628,6 +638,35 @@ int hio_sys_waitmux (hio_t* hio, const hio_ntime_t* tmout, hio_sys_mux_evtcb_t e
|
||||
event_handler (hio, dev, events, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
|
||||
/* TODO: not complete */
|
||||
hio_sys_mux_t* mux = &hio->sysdep->mux;
|
||||
struct timeval tv;
|
||||
struct rfds, wfds;
|
||||
int n;
|
||||
|
||||
tv.tv_sec = tmout->sec;
|
||||
tv.tv_usec = tmout->nsec / HIO_NSEC_PER_USEC;
|
||||
|
||||
rfds = mux->rfds;
|
||||
wfds = mux->wfds;
|
||||
|
||||
n = select(mux->maxfd + 1, rfds, wfds, NULL, &tv);
|
||||
if (n <= -1)
|
||||
{
|
||||
if (errno == EINTR) return 0; /* it's actually ok */
|
||||
/* other errors are critical - EBADF, EFAULT, EINVAL */
|
||||
hio_seterrwithsyserr (hio, 0, errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (FD_ISSET(rfds, xxx))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#elif defined(USE_KQUEUE)
|
||||
|
||||
hio_sys_mux_t* mux = &hio->sysdep->mux;
|
||||
|
@ -69,6 +69,14 @@ struct hio_sys_mux_t
|
||||
int ctrlp[2];
|
||||
};
|
||||
|
||||
#elif defined(USE_SELECT)
|
||||
struct hio_sys_mux_t
|
||||
{
|
||||
fd_set rfds;
|
||||
fd_set wfds;
|
||||
};
|
||||
|
||||
|
||||
#elif defined(USE_KQUEUE)
|
||||
|
||||
struct hio_sys_mux_t
|
||||
|
Loading…
Reference in New Issue
Block a user