mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 07:28:13 +08:00
unbroke unit test
This commit is contained in:
parent
9c22771a43
commit
fd7dc33645
@ -377,13 +377,14 @@ static int ts2(struct mg_connection *conn) {
|
||||
static const char *test_server(void) {
|
||||
char buf1[100] = "", buf2[100] = "";
|
||||
struct mg_server *server = mg_create_server((void *) "foo", evh1);
|
||||
struct mg_connection *conn;
|
||||
|
||||
ASSERT(server != NULL);
|
||||
ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL);
|
||||
ASSERT(mg_set_option(server, "document_root", ".") == NULL);
|
||||
|
||||
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf1) == 1);
|
||||
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf2) == 1);
|
||||
ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
|
||||
ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
|
||||
|
||||
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
|
||||
ASSERT(strcmp(buf1, "foo ? 127.0.0.1") == 0);
|
||||
@ -460,13 +461,14 @@ static int cb3(struct mg_connection *conn) {
|
||||
static const char *test_mg_connect(void) {
|
||||
char buf2[40] = "", buf3[40] = "", buf4[40] = "";
|
||||
struct mg_server *server = mg_create_server(NULL, NULL); // cb4h
|
||||
struct mg_connection *conn;
|
||||
|
||||
ASSERT(mg_set_option(server, "listening_port", LISTENING_ADDR) == NULL);
|
||||
ASSERT(mg_set_option(server, "document_root", ".") == NULL);
|
||||
ASSERT(mg_connect(server, "", 0, 0, NULL, NULL) == 0);
|
||||
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf2) == 1);
|
||||
ASSERT(mg_connect(server, "127.0.0.1", 29, 0, cb3, buf3) == 1);
|
||||
ASSERT(mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0, buf4) == 1);
|
||||
ASSERT(mg_connect(server, "", 0, 0) == NULL);
|
||||
ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
|
||||
ASSERT((conn = mg_connect(server, "127.0.0.1", 29, 0)) != NULL);
|
||||
ASSERT((conn = mg_connect(server, "127.0.0.1", atoi(HTTP_PORT), 0)) != NULL);
|
||||
|
||||
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
|
||||
|
||||
@ -572,8 +574,7 @@ static const char *test_rewrites(void) {
|
||||
ASSERT(mg_set_option(server, "url_rewrites", "/xx=./mongoose.h") == NULL);
|
||||
|
||||
ASSERT(mg_connect(server, "127.0.0.1",
|
||||
atoi(mg_get_option(server, "listening_port")),
|
||||
0, us1, buf1) == 1);
|
||||
atoi(mg_get_option(server, "listening_port")), 0) != NULL);
|
||||
|
||||
{ int i; for (i = 0; i < 50; i++) mg_poll_server(server, 1); }
|
||||
//printf("[%s]\n", buf1);
|
||||
|
13
mongoose.c
13
mongoose.c
@ -4139,7 +4139,7 @@ static void call_http_client_handler(struct connection *conn, int code) {
|
||||
conn->mg_conn.content_len = conn->ns_conn->recv_iobuf.len;
|
||||
}
|
||||
conn->mg_conn.content = conn->ns_conn->recv_iobuf.buf;
|
||||
if (call_user(conn, -1) || code == MG_CONNECT_FAILURE ||
|
||||
if (call_user(conn, MG_CONNECT) || code == MG_CONNECT_FAILURE ||
|
||||
code == MG_DOWNLOAD_FAILURE) {
|
||||
conn->ns_conn->flags |= NSF_CLOSE_IMMEDIATELY;
|
||||
}
|
||||
@ -4553,13 +4553,10 @@ static void mg_ev_handler(struct ns_connection *nc, enum ns_event ev, void *p) {
|
||||
break;
|
||||
|
||||
case NS_CONNECT:
|
||||
{
|
||||
int ok = * (int *) p;
|
||||
conn->mg_conn.status_code = ok == 0 ?
|
||||
MG_CONNECT_SUCCESS : MG_CONNECT_FAILURE;
|
||||
if (call_user(conn, MG_CONNECT) != 0 || ok != 0) {
|
||||
nc->flags |= NSF_CLOSE_IMMEDIATELY;
|
||||
}
|
||||
conn->mg_conn.status_code = * (int *) p;
|
||||
if (conn->mg_conn.status_code != 0 ||
|
||||
call_user(conn, MG_CONNECT) == MG_FALSE) {
|
||||
nc->flags |= NSF_CLOSE_IMMEDIATELY;
|
||||
}
|
||||
break;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user