minor httpd refactoring
This commit is contained in:
parent
7c31be31c3
commit
fcd14fff1c
@ -56,14 +56,22 @@ For additional command line options to @b configure, run @b configure @b --help.
|
||||
|
||||
@subsection crosscompile_win32 CROSS-COMPILING FOR WIN32
|
||||
|
||||
While the package does not provide any build files for native WIN32 compilers,
|
||||
you can cross-compile it for WIN32 with a cross-compiler. Get a cross-compiler
|
||||
installed first and run @b configure with a host and a target.
|
||||
While the package does not provide build files for native WIN32/WIN64 compilers,
|
||||
you can cross-compile it for WIN32/WIN64 with a cross-compiler. Get a
|
||||
cross-compiler installed first and run @b configure with a host and a target.
|
||||
|
||||
With MINGW32, you may run @b configure as shown below:
|
||||
With MINGW-W64, you may run @b configure as shown below for WIN32:
|
||||
|
||||
@code
|
||||
$ ./configure --host=i586-mingw32msvc --target=i586-mingw32msvc
|
||||
$ ./configure --host=i686-w64-mingw32 --target=i686-w64-mingw32
|
||||
$ make
|
||||
$ make install
|
||||
@endcode
|
||||
|
||||
With MINGW-W64, you may run @b configure as shown below for WIN64:
|
||||
|
||||
@code
|
||||
$ ./configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32
|
||||
$ make
|
||||
$ make install
|
||||
@endcode
|
||||
@ -92,6 +100,4 @@ Under the wide character mode:
|
||||
- #qse_char_t maps to #qse_wchar_t.
|
||||
|
||||
#qse_mchar_t maps to @b char and #qse_wchar_t maps to @b wchar_t or equivalent.
|
||||
|
||||
|
||||
*/
|
||||
|
@ -458,6 +458,7 @@ static void delete_from_client_array (qse_httpd_t* httpd, int fd)
|
||||
|
||||
qse_htrd_close (array->data[fd].htrd);
|
||||
array->data[fd].htrd = QSE_NULL;
|
||||
qse_fprintf (QSE_STDERR, QSE_T("Debug: closing socket %d\n"), array->data[fd].handle.i);
|
||||
close (array->data[fd].handle.i);
|
||||
array->size--;
|
||||
}
|
||||
@ -777,6 +778,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Debug: connection closed %d\n"), client->handle.
|
||||
/* feed may have called the request callback multiple times...
|
||||
* that's because we don't know how many valid requests
|
||||
* are included in 'buf' */
|
||||
qse_fprintf (QSE_STDERR, QSE_T("Debug: read from a client %d\n"), client->handle.i);
|
||||
httpd->errnum = QSE_HTTPD_ENOERR;
|
||||
if (qse_htrd_feed (client->htrd, buf, m) <= -1)
|
||||
{
|
||||
|
@ -526,6 +526,7 @@ qse_httpd_task_t* qse_httpd_entaskfile (
|
||||
qse_httpd_task_t task;
|
||||
task_file_t data;
|
||||
|
||||
qse_printf (QSE_T("Debug: sending file to %d\n"), client->handle.i);
|
||||
QSE_MEMSET (&data, 0, QSE_SIZEOF(data));
|
||||
data.handle = handle;
|
||||
data.offset = offset;
|
||||
@ -608,12 +609,16 @@ static int task_main_dir (
|
||||
* the size of the buffer arrray, you should check this size.
|
||||
*/
|
||||
|
||||
#define SIZE_CHLEN 4
|
||||
#define SIZE_CHLENCRLF 2
|
||||
#define SIZE_CHENDCRLF 2
|
||||
|
||||
/* reserve space to fill with the chunk length
|
||||
* 4 for the actual chunk length and +2 for \r\n */
|
||||
ctx->buflen = 4 + 2;
|
||||
ctx->buflen = SIZE_CHLEN + SIZE_CHLENCRLF;
|
||||
|
||||
/* free space remaing in the buffer for the chunk data */
|
||||
ctx->bufrem = QSE_COUNTOF(ctx->buf) - ctx->buflen - 2;
|
||||
ctx->bufrem = QSE_COUNTOF(ctx->buf) - ctx->buflen - CHENDCRLF;
|
||||
|
||||
if (ctx->footer_pending)
|
||||
{
|
||||
@ -629,9 +634,12 @@ static int task_main_dir (
|
||||
}
|
||||
|
||||
ctx->buflen += x;
|
||||
ctx->chunklen = ctx->buflen - 5;
|
||||
ctx->chunklen = ctx->buflen - 5; /* -5 for \r\n0\r\n added above */
|
||||
|
||||
/* CHENDCRLF */
|
||||
ctx->buf[ctx->buflen++] = '\r';
|
||||
ctx->buf[ctx->buflen++] = '\n';
|
||||
|
||||
goto set_chunklen;
|
||||
}
|
||||
|
||||
@ -675,6 +683,8 @@ static int task_main_dir (
|
||||
{
|
||||
ctx->footer_pending = 1;
|
||||
ctx->chunklen = ctx->buflen;
|
||||
|
||||
/* CHENDCRLF */
|
||||
ctx->buf[ctx->buflen++] = '\r';
|
||||
ctx->buf[ctx->buflen++] = '\n';
|
||||
}
|
||||
@ -682,6 +692,8 @@ static int task_main_dir (
|
||||
{
|
||||
ctx->buflen += x;
|
||||
ctx->chunklen = ctx->buflen - 5;
|
||||
|
||||
/* CHENDCRLF */
|
||||
ctx->buf[ctx->buflen++] = '\r';
|
||||
ctx->buf[ctx->buflen++] = '\n';
|
||||
}
|
||||
@ -702,6 +714,8 @@ static int task_main_dir (
|
||||
{
|
||||
/* buffer not large enough to hold this entry */
|
||||
ctx->chunklen = ctx->buflen;
|
||||
|
||||
/* CHENDCRLF */
|
||||
ctx->buf[ctx->buflen++] = '\r';
|
||||
ctx->buf[ctx->buflen++] = '\n';
|
||||
break;
|
||||
@ -718,12 +732,17 @@ static int task_main_dir (
|
||||
while (1);
|
||||
|
||||
set_chunklen:
|
||||
/* right alignment with space padding on the left */
|
||||
x = snprintf (
|
||||
ctx->buf, (4 + 2) - 1,
|
||||
"%*lX", (int)(4 + 2 - 2),
|
||||
(unsigned long)(ctx->chunklen - (4 + 2)));
|
||||
ctx->buf, (SIZE_CHLEN + SIZE_CHLENCRLF) - 1,
|
||||
"%*lX", (int)(SIZE_CHLEN + SIZE_CHLENCRLF - 2),
|
||||
(unsigned long)(ctx->chunklen - (SIZE_CHLEN + SIZE_CHLENCRLF)));
|
||||
|
||||
/* CHLENCRLF */
|
||||
ctx->buf[x] = '\r';
|
||||
ctx->buf[x+1] = '\n';
|
||||
|
||||
/* skip leading space padding */
|
||||
for (x = 0; ctx->buf[x] == ' '; x++) ctx->buflen--;
|
||||
ctx->bufpos = x;
|
||||
|
||||
@ -731,6 +750,8 @@ send_dirlist:
|
||||
n = send (client->handle.i, &ctx->buf[ctx->bufpos], ctx->buflen, 0);
|
||||
if (n <= -1) return -1;
|
||||
|
||||
/* NOTE if (n == 0), it will enter an infinite loop */
|
||||
|
||||
ctx->bufpos += n;
|
||||
ctx->buflen -= n;
|
||||
return (ctx->bufpos < ctx->buflen || ctx->footer_pending || ctx->dent)? 1: 0;
|
||||
|
Loading…
Reference in New Issue
Block a user