Beispiel #1
0
/*
 * Create a socket, set the initial listen() state, then update the queue
 * depth using listen().  Check that the backlog is as expected after both
 * the first and second listen().
 */
static int
socket_listen_update(int domain, int type, int protocol, int backlog,
    int update_backlog, int listen_backlog_assertion,
    int update_backlog_assertion, int *sockp, const char *domainstring,
    const char *typestring, const char *testclass, const char *test)
{
	int backlog_retrieved, sock;

	sock = socket(PF_INET, SOCK_STREAM, 0);
	if (sock < 0) {
		warn("%s: %s: socket_listen_update: socket(%s, %s)",
		    testclass, test, domainstring, typestring);
		return (-1);
	}

	if (listen(sock, backlog) < 0) {
		warn("%s: %s: socket_listen_update: initial listen(, %d)",
		    testclass, test, backlog);
		close(sock);
		return (-1);
	}

	if (socket_get_backlog(sock, &backlog_retrieved, testclass, test,
	    "socket_listen_update") < 0) {
		close(sock);
		return (-1);
	}

	if (backlog_retrieved != listen_backlog_assertion) {
		warnx("%s: %s: socket_listen_update: initial backlog is %d "
		    "not %d", testclass, test, backlog_retrieved,
		    listen_backlog_assertion);
		close(sock);
		return (-1);
	}

	if (listen(sock, update_backlog) < 0) {
		warn("%s: %s: socket_listen_update: update listen(, %d)",
		    testclass, test, update_backlog);
		close(sock);
		return (-1);
	}

	if (socket_get_backlog(sock, &backlog_retrieved, testclass, test,
	    "socket_listen_update") < 0) {
		close(sock);
		return (-1);
	}

	if (backlog_retrieved != update_backlog_assertion) {
		warnx("%s: %s: socket_listen_update: updated backlog is %d "
		    "not %d", testclass, test, backlog_retrieved,
		    update_backlog_assertion);
		close(sock);
		return (-1);
	}

	*sockp = sock;
	return (0);
}
Beispiel #2
0
/*
 * Create a socket, check the queue limit on creation, perform a listen(),
 * and make sure that the limit was set as expected by listen().
 */
static int
socket_listen(int domain, int type, int protocol, int backlog,
    int create_backlog_assertion, int listen_backlog_assertion, int *sockp,
    const char *domainstring, const char *typestring, const char *testclass,
    const char *test)
{
	int backlog_retrieved, sock;

	sock = socket(domain, type, protocol);
	if (sock < 0) {
		warn("%s: %s: socket_listen: socket(%s, %s)", testclass,
		    test, domainstring, typestring);
		close(sock);
		return (-1);
	}

	if (socket_get_backlog(sock, &backlog_retrieved, testclass, test,
	    "socket_listen") < 0) {
		close(sock);
		return (-1);
	}

	if (backlog_retrieved != create_backlog_assertion) {
		warnx("%s: %s: socket_listen: create backlog is %d not %d",
		    testclass, test, backlog_retrieved,
		    create_backlog_assertion);
		close(sock);
		return (-1);
	}

	if (listen(sock, backlog) < 0) {
		warn("%s: %s: socket_listen: listen(, %d)", testclass, test,
		    backlog);
		close(sock);
		return (-1);
	}

	if (socket_get_backlog(sock, &backlog_retrieved, testclass, test,
	    "socket_listen") < 0) {
		close(sock);
		return (-1);
	}

	if (backlog_retrieved != listen_backlog_assertion) {
		warnx("%s: %s: socket_listen: listen backlog is %d not %d",
		    testclass, test, backlog_retrieved,
		    listen_backlog_assertion);
		close(sock);
		return (-1);
	}

	*sockp = sock;
	return (0);
}