Ejemplo n.º 1
0
// sets errno on error
int socket_connect(Socket *socket, struct sockaddr *address, int length) {
	if (connect(socket->handle, (struct sockaddr *)address, length) < 0) {
		return -1;
	}

	return socket_prepare(socket);
}
Ejemplo n.º 2
0
// sets errno on error
int socket_accept_platform(Socket *socket, Socket *accepted_socket,
                           struct sockaddr *address, socklen_t *length) {
	int saved_errno;

	// accept socket
	accepted_socket->handle = accept(socket->handle, address, length);

	if (accepted_socket->handle == IO_HANDLE_INVALID) {
		errno = ERRNO_WINAPI_OFFSET + WSAGetLastError();

		return -1;
	}

	accepted_socket->family = address->sa_family;
	accepted_socket->base.read_handle = accepted_socket->handle;
	accepted_socket->base.write_handle = accepted_socket->handle;

	// prepare socket
	if (socket_prepare(accepted_socket) < 0) {
		saved_errno = errno;

		closesocket(accepted_socket->handle);

		errno = saved_errno;

		return -1;
	}

	return 0;
}
Ejemplo n.º 3
0
// sets errno on error
int socket_bind(Socket *socket, const struct sockaddr *address, socklen_t length) {
	if (bind(socket->handle, address, length) < 0) {
		return -1;
	}

	return socket_prepare(socket);
}
Ejemplo n.º 4
0
// sets errno on error
int socket_connect(Socket *socket, struct sockaddr *address, int length) {
	if (connect(socket->handle, address, length) == SOCKET_ERROR) {
		errno = ERRNO_WINAPI_OFFSET + WSAGetLastError();

		return -1;
	}

	return socket_prepare(socket);
}
Ejemplo n.º 5
0
// sets errno on error
int socket_bind(Socket *socket, const struct sockaddr *address, socklen_t length) {
	if (bind(socket->handle, address, length) == SOCKET_ERROR) {
		errno = ERRNO_WINAPI_OFFSET + WSAGetLastError();

		return -1;
	}

	return socket_prepare(socket);
}
Ejemplo n.º 6
0
// sets errno on error
int socket_accept_platform(Socket *socket, Socket *accepted_socket,
                           struct sockaddr *address, socklen_t *length) {
	// accept socket
	accepted_socket->handle = accept(socket->handle, address, length);

	if (accepted_socket->handle < 0) {
		return -1;
	}

	accepted_socket->family = address->sa_family;
	accepted_socket->base.read_handle = accepted_socket->handle;
	accepted_socket->base.write_handle = accepted_socket->handle;

	// prepare socket
	if (socket_prepare(accepted_socket) < 0) {
		robust_close(accepted_socket->handle);

		return -1;
	}

	return 0;
}
Ejemplo n.º 7
0
gint httpserver_start (HTTPServer *http_server, http_callback_t user_callback, gpointer user_data)
{
    GError *err = NULL;

    http_server->thread_pool = g_thread_pool_new (thread_pool_func, http_server, http_server->max_threads, TRUE, &err);
    if (err != NULL) {
        GST_ERROR ("Create thread pool error %s", err->message);
        g_error_free (err);
        return -1;
    }
    http_server->user_callback = user_callback;
    http_server->user_data = user_data;
    if (socket_prepare (http_server) != 0) {
        return 1;
    }

    http_server->listen_thread = g_thread_new ("listen_thread", listen_thread, http_server);
    http_server->idle_thread = g_thread_new ("idle_thread", idle_thread, http_server);
    http_server->block_thread = g_thread_new ("block_thread", block_thread, http_server);

    return 0;
}