Annotation of embedaddon/strongswan/src/libstrongswan/networking/streams/stream_service.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2013 Martin Willi
                      3:  * Copyright (C) 2013 revosec AG
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the
                      7:  * Free Software Foundation; either version 2 of the License, or (at your
                      8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: /**
                     17:  * @defgroup stream_service stream_service
                     18:  * @{ @ingroup streams
                     19:  */
                     20: 
                     21: #ifndef STREAM_SERVICE_H_
                     22: #define STREAM_SERVICE_H_
                     23: 
                     24: typedef struct stream_service_t stream_service_t;
                     25: 
                     26: #include <processing/jobs/job.h>
                     27: #include <networking/streams/stream.h>
                     28: 
                     29: /**
                     30:  * Constructor function prototype for stream_service_t.
                     31:  *
                     32:  * @param uri                  URI to create a stream for
                     33:  * @param backlog              size of the backlog queue, as passed to listen()
                     34:  * @return                             stream instance, NULL on error
                     35:  */
                     36: typedef stream_service_t*(*stream_service_constructor_t)(char *uri, int backlog);
                     37: 
                     38: /**
                     39:  * Service callback routine for accepting client connections.
                     40:  *
                     41:  * The passed stream gets closed/destroyed by the callback caller, unless
                     42:  * TRUE is returned.
                     43:  *
                     44:  * @param data                 user data, as passed during registration
                     45:  * @param stream               accept()ed client connection
                     46:  * @return                             TRUE to keep stream alive, FALSE to destroy it
                     47:  */
                     48: typedef bool (*stream_service_cb_t)(void *data, stream_t *stream);
                     49: 
                     50: /**
                     51:  * A service accepting client connection streams.
                     52:  */
                     53: struct stream_service_t {
                     54: 
                     55:        /**
                     56:         * Start accepting client connections on this stream service.
                     57:         *
                     58:         * To stop accepting connections, pass a NULL callback function.
                     59:         *
                     60:         * @param cb            callback function to call for accepted client streams
                     61:         * @param data          data to pass to callback function
                     62:         * @param prio          job priority to run callback with
                     63:         * @param cncrncy       maximum number of parallel callback invocations
                     64:         */
                     65:        void (*on_accept)(stream_service_t *this,
                     66:                                          stream_service_cb_t cb, void *data,
                     67:                                          job_priority_t prio, u_int cncrncy);
                     68: 
                     69:        /**
                     70:         * Destroy a stream_service_t.
                     71:         */
                     72:        void (*destroy)(stream_service_t *this);
                     73: };
                     74: 
                     75: /**
                     76:  * Create a service from a file descriptor.
                     77:  *
                     78:  * The file descriptor MUST be a socket.
                     79:  *
                     80:  * @param fd           file descriptor to wrap into a stream_service_t
                     81:  * @return                     stream_service instance
                     82:  */
                     83: stream_service_t *stream_service_create_from_fd(int fd);
                     84: 
                     85: #endif /** STREAM_SERVICE_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>