DOMAIN_SERVER(3) Library Functions Manual DOMAIN_SERVER(3) NAME domain_server -- generic DOMAIN server LIBRARY PDEL Library (libpdel, -lpdel) SYNOPSIS #include <sys/types.h> #include <sys/un.h> #include <stdio.h> #include <pdel/net/domain_server.h> struct domain_server * domain_server_start(struct pevent_ctx *ctx, void *cookie, const char *mtype, struct in_addr ip, u_int16_t port, u_int max_conn, u_int conn_timeout, domain_setup_t *setup, domain_handler_t *handler, domain_teardown_t *teardown); void domain_server_stop(struct domain_server **servp); void * domain_server_get_cookie(struct domain_server *serv); struct domain_server * domain_connection_get_server(struct domain_connection *conn); void * domain_connection_get_cookie(struct domain_connection *conn); int domain_connection_get_fd(struct domain_connection *conn); FILE * domain_connection_get_fp(struct domain_connection *conn); void domain_connection_get_peer(struct domain_connection *conn, struct sockaddr_un *sun); DESCRIPTION These functions provide support for implementing DOMAIN servers. domain_server_start() creates a new DOMAIN server listening for connections on IP address ip and port port. Memory for the domain_server is dynami- cally allocated with typed_mem(3) type mtype. At most max_conn simultane- ous connections will be allowed. If conn_timeout is non-zero, then if an attempt to read from or write to a peer blocks for more than conn_timeout seconds, the connection will be terminated. ctx is a pevent(3) event con- text used to listen for incoming connections. The setup, handler, and teardown arguments are pointers to functions having these types: typedef void *domain_setup_t(struct domain_connection *conn); typedef void domain_handler_t(struct domain_connection *conn); typedef void domain_teardown_t(struct domain_connection *conn); Each connection is represented by a domain_connection object. For each new connection, setup() is called to initialize user state for the connection. If setup is unsuccessful, setup() should return NULL and set errno appro- priately, and the connection will be closed. Otherwise, it should return a non-NULL cookie; this cookie can be accessed later in handler() and tear- down() by calling domain_connection_get_cookie(). handler() is used to service the connection. The thread calling this func- tion may be canceled at any cancellation point; therefore, handler() may need to register cleanup hooks to clean up allocated resources should that happen. teardown() is called when handler() returns, or the thread is canceled. If setup() returns successfully, teardown() is guaranteed to be called exactly once. domain_server_stop() stops and destroys a domain_server. All existing con- nection threads are canceled and the current thread blocks until teardown() has been called for each connection. domain_connection_get_peer() retrieves the peer's address. domain_connection_get_server() returns the domain_server object associated with the connection conn. domain_connection_get_fd() returns the DOMAIN socket associated with the connection. domain_connection_get_fp() returns a stream opened on top of the socket for use with stream based I/O. The user code should not close either the socket or the stream; these will be closed automatically when the connection is terminated. RETURN VALUES domain_server_start() returns NULL to indicate an error, with errno set ap- propriately. SEE ALSO libpdel(3), pevent(3), typed_mem(3) HISTORY The PDEL library was developed at Packet Design, LLC. http://www.packetdesign.com/ AUTHORS Archie Cobbs <archie@freebsd.org> Mark Gooderum <markpdel@jumpweb.com> FreeBSD ports 15.quarterly October 25, 2006 DOMAIN_SERVER(3)
NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUES | SEE ALSO | HISTORY | AUTHORS
Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=domain_connection_get_server&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>
