示例#1
0
文件: manos.c 项目: axelc/manos
int
manos_socket_accept_many (int fd, manos_socket_info_t *infos, int len, int *err)
{
	int i = 0;
	
	for (i = 0; i < len; i++) {
		int a = manos_socket_accept (fd, &(infos [i]), err);

		if (a < 0 && *err == 0)
			return i; // Just a wouldblock error
		if (a < 0)
			return -1; // err will be set by manos_socket_accept
	}

	return i;
}
示例#2
0
int
manos_tls_accept (manos_tls_socket_t server, manos_tls_socket_t *client, manos_socket_info_t *info)
{
	int err, inner_err;
	manos_tls_socket_t client_socket;
	
	err = manos_socket_accept (server->socket, info, &inner_err);
	if (err < 0) {
		if (inner_err == 0) {
			return EAGAIN;
		} else {
			return inner_err;
		}
	}

	client_socket = malloc (sizeof (*client_socket));
	if (client_socket == NULL) {
		close (info->fd);
		return ENOMEM;
	}

	memset (client_socket, 0, sizeof (*client_socket));

	client_socket->socket = info->fd;

	err = gnutls_init (&(client_socket->tls_session), GNUTLS_SERVER);
	if (err != 0) {
		close (info->fd);
		if (err != GNUTLS_E_MEMORY_ERROR) {
			gnutls_deinit (client_socket->tls_session);
		} else {
			err = ENOMEM;
		}
		free (client_socket);
		return err;
	}

	gnutls_priority_set (client_socket->tls_session, priority_cache);
	gnutls_credentials_set (client_socket->tls_session, GNUTLS_CRD_CERTIFICATE, server->credentials);
	gnutls_transport_set_ptr (client_socket->tls_session, (gnutls_transport_ptr_t) info->fd);

	*client = client_socket;
	do_handshake(client_socket);

	return 0;
}