added interim patches to httpd for sco
This commit is contained in:
parent
5e85ab6613
commit
578080e071
@ -539,6 +539,7 @@ static int activate_listener (qse_httpd_t* httpd, listener_t* l)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AF_INET6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
{
|
{
|
||||||
addr.in6.sin6_family = l->family;
|
addr.in6.sin6_family = l->family;
|
||||||
@ -547,6 +548,7 @@ static int activate_listener (qse_httpd_t* httpd, listener_t* l)
|
|||||||
/* TODO: addr.in6.sin6_scope_id */
|
/* TODO: addr.in6.sin6_scope_id */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@ -720,7 +722,11 @@ static int accept_client_from_listener (qse_httpd_t* httpd, listener_t* l)
|
|||||||
{
|
{
|
||||||
int flag, c;
|
int flag, c;
|
||||||
sockaddr_t addr;
|
sockaddr_t addr;
|
||||||
|
#ifdef HAVE_SOCKLEN_T
|
||||||
socklen_t addrlen = QSE_SIZEOF(addr);
|
socklen_t addrlen = QSE_SIZEOF(addr);
|
||||||
|
#else
|
||||||
|
int addrlen = QSE_SIZEOF(addr);
|
||||||
|
#endif
|
||||||
qse_httpd_client_t* client;
|
qse_httpd_client_t* client;
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
@ -915,7 +921,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Error: select returned failure - %S\n"), strerro
|
|||||||
if (client->bad)
|
if (client->bad)
|
||||||
{
|
{
|
||||||
/*send (client->handle, i, "INTERNAL SERVER ERROR..", ...);*/
|
/*send (client->handle, i, "INTERNAL SERVER ERROR..", ...);*/
|
||||||
/*shutdown (client->handle.i, 0);*/
|
/*shutdown (client->handle.i, SHUT_RDWR);*/
|
||||||
pthread_mutex_lock (&httpd->client.mutex);
|
pthread_mutex_lock (&httpd->client.mutex);
|
||||||
delete_from_client_array (httpd, fd);
|
delete_from_client_array (httpd, fd);
|
||||||
pthread_mutex_unlock (&httpd->client.mutex);
|
pthread_mutex_unlock (&httpd->client.mutex);
|
||||||
@ -985,6 +991,7 @@ int qse_httpd_loop (qse_httpd_t* httpd, int threaded)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
httpd->stopreq = 0;
|
httpd->stopreq = 0;
|
||||||
|
httpd->threaded = 0;
|
||||||
|
|
||||||
QSE_ASSERTX (httpd->listener.list != QSE_NULL,
|
QSE_ASSERTX (httpd->listener.list != QSE_NULL,
|
||||||
"Add listeners before calling qse_httpd_loop()"
|
"Add listeners before calling qse_httpd_loop()"
|
||||||
@ -1008,11 +1015,12 @@ int qse_httpd_loop (qse_httpd_t* httpd, int threaded)
|
|||||||
pthread_mutex_init (&httpd->client.mutex, QSE_NULL);
|
pthread_mutex_init (&httpd->client.mutex, QSE_NULL);
|
||||||
pthread_cond_init (&httpd->client.cond, QSE_NULL);
|
pthread_cond_init (&httpd->client.cond, QSE_NULL);
|
||||||
|
|
||||||
if (pthread_create (&response_thread_id, QSE_NULL, response_thread, httpd) != 0)
|
if (pthread_create (
|
||||||
|
&response_thread_id, QSE_NULL,
|
||||||
|
response_thread, httpd) != 0)
|
||||||
{
|
{
|
||||||
pthread_cond_destroy (&httpd->client.cond);
|
pthread_cond_destroy (&httpd->client.cond);
|
||||||
pthread_mutex_destroy (&httpd->client.mutex);
|
pthread_mutex_destroy (&httpd->client.mutex);
|
||||||
httpd->threaded = 0;
|
|
||||||
}
|
}
|
||||||
else httpd->threaded = 1;
|
else httpd->threaded = 1;
|
||||||
}
|
}
|
||||||
@ -1028,9 +1036,13 @@ int qse_httpd_loop (qse_httpd_t* httpd, int threaded)
|
|||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
pthread_mutex_lock (&httpd->client.mutex);
|
#if defined(HAVE_PTHREAD)
|
||||||
|
if (httpd->threaded) pthread_mutex_lock (&httpd->client.mutex);
|
||||||
|
#endif
|
||||||
max = make_fd_set_from_client_array (httpd, &r, &w);
|
max = make_fd_set_from_client_array (httpd, &r, &w);
|
||||||
pthread_mutex_unlock (&httpd->client.mutex);
|
#if defined(HAVE_PTHREAD)
|
||||||
|
if (httpd->threaded) pthread_mutex_unlock (&httpd->client.mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
n = select (max + 1, &r, &w, QSE_NULL, &tv);
|
n = select (max + 1, &r, &w, QSE_NULL, &tv);
|
||||||
if (n <= -1)
|
if (n <= -1)
|
||||||
@ -1064,7 +1076,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Error: select returned failure\n"));
|
|||||||
/* let the writing part handle it,
|
/* let the writing part handle it,
|
||||||
* probably in the next iteration */
|
* probably in the next iteration */
|
||||||
qse_httpd_markclientbad (httpd, client);
|
qse_httpd_markclientbad (httpd, client);
|
||||||
shutdown (client->handle.i, 0);
|
shutdown (client->handle.i, SHUT_RDWR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1083,7 +1095,7 @@ qse_fprintf (QSE_STDERR, QSE_T("Error: select returned failure\n"));
|
|||||||
if (client->bad)
|
if (client->bad)
|
||||||
{
|
{
|
||||||
/*send (client->handle, i, "INTERNAL SERVER ERROR..", ...);*/
|
/*send (client->handle, i, "INTERNAL SERVER ERROR..", ...);*/
|
||||||
/*shutdown (client->handle.i, 0);*/
|
/*shutdown (client->handle.i, SHUT_RDWR);*/
|
||||||
|
|
||||||
/*pthread_mutex_lock (&httpd->client.mutex);*/
|
/*pthread_mutex_lock (&httpd->client.mutex);*/
|
||||||
delete_from_client_array (httpd, fd);
|
delete_from_client_array (httpd, fd);
|
||||||
@ -1176,6 +1188,7 @@ static listener_t* parse_listener_string (
|
|||||||
if (*p != QSE_T('/')) goto oops_einval;
|
if (*p != QSE_T('/')) goto oops_einval;
|
||||||
p++; /* skip / */
|
p++; /* skip / */
|
||||||
|
|
||||||
|
#ifdef AF_INET6
|
||||||
if (*p == QSE_T('['))
|
if (*p == QSE_T('['))
|
||||||
{
|
{
|
||||||
/* IPv6 address */
|
/* IPv6 address */
|
||||||
@ -1193,6 +1206,7 @@ static listener_t* parse_listener_string (
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#endif
|
||||||
/* host name or IPv4 address */
|
/* host name or IPv4 address */
|
||||||
tmp.ptr = p;
|
tmp.ptr = p;
|
||||||
while (!QSE_ISSPACE(*p) &&
|
while (!QSE_ISSPACE(*p) &&
|
||||||
@ -1200,7 +1214,9 @@ static listener_t* parse_listener_string (
|
|||||||
*p != QSE_T('\0')) p++;
|
*p != QSE_T('\0')) p++;
|
||||||
tmp.len = p - tmp.ptr;
|
tmp.len = p - tmp.ptr;
|
||||||
ltmp->family = AF_INET;
|
ltmp->family = AF_INET;
|
||||||
|
#ifdef AF_INET6
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ltmp->host = qse_strxdup (tmp.ptr, tmp.len, httpd->mmgr);
|
ltmp->host = qse_strxdup (tmp.ptr, tmp.len, httpd->mmgr);
|
||||||
if (ltmp->host == QSE_NULL) goto oops_enomem;
|
if (ltmp->host == QSE_NULL) goto oops_enomem;
|
||||||
@ -1314,11 +1330,15 @@ static int delete_listeners (qse_httpd_t* httpd, const qse_char_t* uri)
|
|||||||
|
|
||||||
int qse_httpd_addlisteners (qse_httpd_t* httpd, const qse_char_t* uri)
|
int qse_httpd_addlisteners (qse_httpd_t* httpd, const qse_char_t* uri)
|
||||||
{
|
{
|
||||||
|
#if defined(HAVE_PTHREAD)
|
||||||
int n;
|
int n;
|
||||||
pthread_mutex_lock (&httpd->listener.mutex);
|
pthread_mutex_lock (&httpd->listener.mutex);
|
||||||
n = add_listeners (httpd, uri);
|
n = add_listeners (httpd, uri);
|
||||||
pthread_mutex_unlock (&httpd->listener.mutex);
|
pthread_mutex_unlock (&httpd->listener.mutex);
|
||||||
return n;
|
return n;
|
||||||
|
#else
|
||||||
|
return add_listeners (httpd, uri);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -34,12 +34,18 @@
|
|||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SHUT_RDWR
|
||||||
|
# define SHUT_RDWR 2
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct client_array_t client_array_t;
|
typedef struct client_array_t client_array_t;
|
||||||
|
|
||||||
union sockaddr_t
|
union sockaddr_t
|
||||||
{
|
{
|
||||||
struct sockaddr_in in4;
|
struct sockaddr_in in4;
|
||||||
|
#ifdef AF_INET6
|
||||||
struct sockaddr_in6 in6;
|
struct sockaddr_in6 in6;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef union sockaddr_t sockaddr_t;
|
typedef union sockaddr_t sockaddr_t;
|
||||||
@ -90,7 +96,9 @@ struct listener_t
|
|||||||
union
|
union
|
||||||
{
|
{
|
||||||
struct in_addr in4;
|
struct in_addr in4;
|
||||||
|
#ifdef AF_INET6
|
||||||
struct in6_addr in6;
|
struct in6_addr in6;
|
||||||
|
#endif
|
||||||
} addr;
|
} addr;
|
||||||
|
|
||||||
int port;
|
int port;
|
||||||
@ -105,9 +113,7 @@ struct qse_httpd_t
|
|||||||
qse_httpd_cbs_t* cbs;
|
qse_httpd_cbs_t* cbs;
|
||||||
|
|
||||||
int stopreq;
|
int stopreq;
|
||||||
#if defined(HAVE_PTHREAD)
|
|
||||||
int threaded;
|
int threaded;
|
||||||
#endif
|
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -25,16 +25,36 @@
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef HAVE_SYS_SENDFILE_H
|
|
||||||
#include <sys/sendfile.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define MAX_SENDFILE_SIZE 4096
|
#define MAX_SENDFILE_SIZE 4096
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_SENDFILE_H
|
||||||
|
# include <sys/sendfile.h>
|
||||||
|
#else
|
||||||
|
qse_ssize_t sendfile (
|
||||||
|
int out_fd, int in_fd, qse_foff_t* offset, qse_size_t count)
|
||||||
|
{
|
||||||
|
qse_mchar_t buf[MAX_SENDFILE_SIZE];
|
||||||
|
qse_ssize_t n;
|
||||||
|
|
||||||
|
if (offset && lseek (in_fd, *offset, SEEK_SET) != *offset)
|
||||||
|
return (qse_ssize_t)-1;
|
||||||
|
|
||||||
|
if (count > QSE_COUNTOF(buf)) count = QSE_COUNTOF(buf);
|
||||||
|
n = read (in_fd, buf, count);
|
||||||
|
if (n == (qse_ssize_t)-1 || n == 0) return n;
|
||||||
|
|
||||||
|
n = write (out_fd, buf, n);
|
||||||
|
if (n > 0 && offset) *offset = *offset + n;
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
static int task_main_disconnect (
|
static int task_main_disconnect (
|
||||||
@ -481,6 +501,7 @@ static int task_main_path (
|
|||||||
|
|
||||||
if (data->range.to >= st.st_size) data->range.to = st.st_size - 1;
|
if (data->range.to >= st.st_size) data->range.to = st.st_size - 1;
|
||||||
|
|
||||||
|
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||||
x = qse_httpd_entaskformat (httpd, client,
|
x = qse_httpd_entaskformat (httpd, client,
|
||||||
QSE_MT("HTTP/%d.%d 206 Partial content\r\nContent-Length: %llu\r\nContent-Location: %s\r\nContent-Range: bytes %llu-%llu/%llu\r\n\r\n"),
|
QSE_MT("HTTP/%d.%d 206 Partial content\r\nContent-Length: %llu\r\nContent-Location: %s\r\nContent-Range: bytes %llu-%llu/%llu\r\n\r\n"),
|
||||||
data->version.major,
|
data->version.major,
|
||||||
@ -489,8 +510,20 @@ static int task_main_path (
|
|||||||
data->name,
|
data->name,
|
||||||
(unsigned long long)data->range.from,
|
(unsigned long long)data->range.from,
|
||||||
(unsigned long long)data->range.to,
|
(unsigned long long)data->range.to,
|
||||||
st.st_size
|
(unsigned long long)st.st_size
|
||||||
);
|
);
|
||||||
|
#else
|
||||||
|
x = qse_httpd_entaskformat (httpd, client,
|
||||||
|
QSE_MT("HTTP/%d.%d 206 Partial content\r\nContent-Length: %lu\r\nContent-Location: %s\r\nContent-Range: bytes %lu-%lu/%lu\r\n\r\n"),
|
||||||
|
data->version.major,
|
||||||
|
data->version.minor,
|
||||||
|
(unsigned long)(data->range.to - data->range.from + 1),
|
||||||
|
data->name,
|
||||||
|
(unsigned long)data->range.from,
|
||||||
|
(unsigned long)data->range.to,
|
||||||
|
(unsigned long)st.st_size
|
||||||
|
);
|
||||||
|
#endif
|
||||||
if (x <= -1) goto oops;
|
if (x <= -1) goto oops;
|
||||||
|
|
||||||
x = qse_httpd_entaskfile (
|
x = qse_httpd_entaskfile (
|
||||||
@ -504,6 +537,7 @@ static int task_main_path (
|
|||||||
{
|
{
|
||||||
/* TODO: int64 format.... don't hard code it llu */
|
/* TODO: int64 format.... don't hard code it llu */
|
||||||
|
|
||||||
|
#if (QSE_SIZEOF_LONG_LONG > 0)
|
||||||
x = qse_httpd_entaskformat (httpd, client,
|
x = qse_httpd_entaskformat (httpd, client,
|
||||||
QSE_MT("HTTP/%d.%d 200 OK\r\nContent-Length: %llu\r\nContent-Location: %s\r\n\r\n"),
|
QSE_MT("HTTP/%d.%d 200 OK\r\nContent-Length: %llu\r\nContent-Location: %s\r\n\r\n"),
|
||||||
data->version.major,
|
data->version.major,
|
||||||
@ -511,6 +545,15 @@ static int task_main_path (
|
|||||||
(unsigned long long)st.st_size,
|
(unsigned long long)st.st_size,
|
||||||
data->name
|
data->name
|
||||||
);
|
);
|
||||||
|
#else
|
||||||
|
x = qse_httpd_entaskformat (httpd, client,
|
||||||
|
QSE_MT("HTTP/%d.%d 200 OK\r\nContent-Length: %lu\r\nContent-Location: %s\r\n\r\n"),
|
||||||
|
data->version.major,
|
||||||
|
data->version.minor,
|
||||||
|
(unsigned long)st.st_size,
|
||||||
|
data->name
|
||||||
|
);
|
||||||
|
#endif
|
||||||
if (x <= -1) goto oops;
|
if (x <= -1) goto oops;
|
||||||
|
|
||||||
x = qse_httpd_entaskfile (httpd, client, handle, 0, st.st_size);
|
x = qse_httpd_entaskfile (httpd, client, handle, 0, st.st_size);
|
||||||
|
Loading…
Reference in New Issue
Block a user