Esempio n. 1
0
void* http_server_create(const char* ip, int port)
{
	socket_t socket;
	struct http_server_t *ctx;
	struct aio_tcp_transport_handler_t handler;

	// create server socket
	socket = tcpserver_create(ip, port, 64);
	if(socket_invalid == socket)
	{
		printf("http_server_create(%s, %d): create socket error.\n", ip, port);
		return NULL;
	}

	ctx = (struct http_server_t*)malloc(sizeof(ctx[0]));
	if(!ctx)
		return NULL;

	memset(ctx, 0, sizeof(ctx[0]));
	handler.onconnected = http_session_onconnected;
	handler.ondisconnected = http_session_ondisconnected;
	handler.onrecv = http_session_onrecv;
	handler.onsend = http_session_onsend;
	ctx->transport = aio_tcp_transport_create(socket, &handler, ctx);
	if(!ctx->transport)
	{
		printf("http_server_create(%s, %d) create aio transport error.\n", ip, port);
		http_server_destroy(ctx);
		return NULL;
	}

	return ctx;
}
Esempio n. 2
0
void hls_server_test(const char* ip, int port)
{
	aio_socket_init(1);
	http_server_init();
	void* http = http_server_create(ip, port);
	http_server_set_handler(http, hls_server_onhttp, http);

	// http process
	while(aio_socket_process(1000) >= 0)
	{
	}

	http_server_destroy(http);
	http_server_cleanup();
	aio_socket_clean();
}
Esempio n. 3
0
int main( int /*argc*/, char** /*argv*/ )
{
	http_server_t server = http_server_create( 1337, 16, 0x0 );
	if( server == 0x0 )
		return 1;

	bool running = true;
	while( running )
	{
		http_server_request* req;
		while( ( req = http_server_poll( server, 0x0 ) ) != 0x0 )
		{
			switch( req->type )
			{
				case HTTP_SERVER_REQUEST_GET:
					if(false /*not file exists*/)
					{
						http_server_fail_request( req, 404 ); // method not allowed.
					}
					else
					{
						http_server_complete_request( req, "application/json", "{ \"test\" : true }", 6 );
					}
					break;

				case HTTP_SERVER_REQUEST_HEAD:
				case HTTP_SERVER_REQUEST_POST:
				case HTTP_SERVER_REQUEST_PUT:
				case HTTP_SERVER_REQUEST_DELETE:
					http_server_fail_request( req, 405 ); // method not allowed.
					break;
				default:
					http_server_fail_request( req, 500 ); // internal server error.
					break;
			}
		}
	}

	http_server_destroy( server );
}
Esempio n. 4
0
// Cleanup channel
static void http_channel_destroy(IOCHAN i)
{
    struct http_channel *s = iochan_getdata(i);
    http_server_t http_server;

    if (s->proxy)
    {
        if (s->proxy->iochan)
        {
#ifdef WIN32
            closesocket(iochan_getfd(s->proxy->iochan));
#else
            close(iochan_getfd(s->proxy->iochan));
#endif
            iochan_destroy(s->proxy->iochan);
        }
        http_buf_destroy_queue(s->http_server, s->proxy->oqueue);
        xfree(s->proxy);
    }
    http_buf_destroy_queue(s->http_server, s->iqueue);
    http_buf_destroy_queue(s->http_server, s->oqueue);
    http_fire_observers(s);
    http_destroy_observers(s);

    http_server = s->http_server; /* save it for destroy (decref) */

    http_server_destroy(http_server);

#ifdef WIN32
    closesocket(iochan_getfd(i));
#else
    close(iochan_getfd(i));
#endif
    iochan_destroy(i);
    nmem_destroy(s->nmem);
    wrbuf_destroy(s->wrbuf);
    xfree(s);
}
Esempio n. 5
0
void dash_dynamic_test(const char* ip, int port, const char* file, int width, int height)
{
    std::shared_ptr<dash_playlist_t> live(new dash_playlist_t());
    live->mpd = dash_mpd_create(DASH_DYNAMIC, dash_mpd_onsegment, live.get());
    live->name = "live";
    live->width = width;
    live->height = height;
    live->adapation_audio = live->adapation_video = -1;

    aio_worker_init(4);
	http_server_t* http = http_server_create(ip, port);
	http_server_set_handler(http, http_server_route, live.get());
	http_server_addroute("/live/", dash_server_onlive);
	http_server_addroute("/vod/", dash_server_onvod);

    // live worker
    dash_live_worker(file, live.get());
    
	http_server_destroy(http);
    aio_worker_clean(4);

    dash_mpd_destroy(live->mpd);
}
Esempio n. 6
0
WebSession::~WebSession()
{
	http_server_destroy(&m_http);
	dlog_log("client[%s.%d] disconnected.\n", m_ip.c_str(), m_port);
}