plibsys 0.0.5
psocket.h
Go to the documentation of this file.
1/*
2 * The MIT License
3 *
4 * Copyright (C) 2010-2016 Alexander Saprykin <saprykin.spb@gmail.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * 'Software'), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
148#if !defined (PLIBSYS_H_INSIDE) && !defined (PLIBSYS_COMPILATION)
149# error "Header files shouldn't be included directly, consider using <plibsys.h> instead."
150#endif
151
152#ifndef PLIBSYS_HEADER_PSOCKET_H
153#define PLIBSYS_HEADER_PSOCKET_H
154
155#include <pmacros.h>
156#include <psocketaddress.h>
157#include <perror.h>
158
160
169
177
183
189
191typedef struct PSocket_ PSocket;
192
209 PError **error);
210
229 PSocketType type,
230 PSocketProtocol protocol,
231 PError **error);
232
241
256
265
275
296
310
329
350
364 PError **error);
365
382 PError **error);
383
396
409
433 PError **error);
434
445 pboolean keepalive);
446
460 pboolean blocking);
461
476 pint backlog);
477
488 pint timeout);
489
534 PSocketAddress *address,
535 pboolean allow_reuse,
536 PError **error);
537
567 PSocketAddress *address,
568 PError **error);
569
589 PError **error);
590
604 PError **error);
605
626 pchar *buffer,
627 psize buflen,
628 PError **error);
629
651 PSocketAddress **address,
652 pchar *buffer,
653 psize buflen,
654 PError **error);
655
673 const pchar *buffer,
674 psize buflen,
675 PError **error);
676
696 PSocketAddress *address,
697 const pchar *buffer,
698 psize buflen,
699 PError **error);
700
714 PError **error);
715
732 pboolean shutdown_read,
733 pboolean shutdown_write,
734 PError **error);
735
743
756 psize size,
757 PError **error);
758
774 PSocketIOCondition condition,
775 PError **error);
776
778
779#endif /* PLIBSYS_HEADER_PSOCKET_H */
Error report system.
struct PError_ PError
Opaque data structure for an error object.
Definition perror.h:68
Miscellaneous macros.
#define P_BEGIN_DECLS
Starts .h file declarations to be exported as C functions.
Definition pmacros.h:298
#define P_END_DECLS
Closes .h file declarations to be exported as C functions, should be always used after P_BEGIN_DECLS.
Definition pmacros.h:299
#define P_LIB_API
Exports a symbol from a shared library.
Definition pmacros.h:138
P_LIB_API pboolean p_socket_close(PSocket *socket, PError **error)
Closes a socket.
P_LIB_API pboolean p_socket_check_connect_result(PSocket *socket, PError **error)
Checks a connection state after calling p_socket_connect().
P_LIB_API pssize p_socket_receive_from(const PSocket *socket, PSocketAddress **address, pchar *buffer, psize buflen, PError **error)
Receives data from a given socket and saves a remote address.
P_LIB_API PSocketType p_socket_get_type(const PSocket *socket)
Gets a socket type.
P_LIB_API PSocket * p_socket_accept(const PSocket *socket, PError **error)
Accepts a socket incoming connection.
P_LIB_API PSocketAddress * p_socket_get_remote_address(const PSocket *socket, PError **error)
Gets a socket remote endpoint address.
enum PSocketDirection_ PSocketDirection
Socket direction for data operations.
P_LIB_API PSocket * p_socket_new(PSocketFamily family, PSocketType type, PSocketProtocol protocol, PError **error)
Creates a new PSocket object.
P_LIB_API pssize p_socket_receive(const PSocket *socket, pchar *buffer, psize buflen, PError **error)
Receives data from a given socket.
enum PSocketIOCondition_ PSocketIOCondition
Socket IO waiting (polling) conditions.
P_LIB_API void p_socket_set_blocking(PSocket *socket, pboolean blocking)
Sets a socket blocking mode.
enum PSocketType_ PSocketType
Socket types.
P_LIB_API void p_socket_set_timeout(PSocket *socket, pint timeout)
Sets a socket timeout value for blocking I/O operations.
P_LIB_API pboolean p_socket_listen(PSocket *socket, PError **error)
Puts a socket into a listening state.
P_LIB_API pint p_socket_get_timeout(const PSocket *socket)
Gets a socket timeout for blocking I/O operations.
P_LIB_API pint p_socket_get_fd(const PSocket *socket)
Gets an underlying file descriptor of a socket.
P_LIB_API pboolean p_socket_shutdown(PSocket *socket, pboolean shutdown_read, pboolean shutdown_write, PError **error)
Shutdowns a full-duplex socket data transfer link.
P_LIB_API pint p_socket_get_listen_backlog(const PSocket *socket)
Gets a socket listen backlog parameter.
P_LIB_API void p_socket_free(PSocket *socket)
Closes a socket (if not closed yet) and frees its resources.
P_LIB_API pboolean p_socket_set_buffer_size(const PSocket *socket, PSocketDirection dir, psize size, PError **error)
Sets the socket buffer size for a given data transfer direction.
P_LIB_API PSocket * p_socket_new_from_fd(pint fd, PError **error)
Creates a new PSocket object from a file descriptor.
enum PSocketProtocol_ PSocketProtocol
Socket protocols specified by the IANA.
P_LIB_API PSocketAddress * p_socket_get_local_address(const PSocket *socket, PError **error)
Gets a socket local (bound) address.
P_LIB_API pboolean p_socket_io_condition_wait(const PSocket *socket, PSocketIOCondition condition, PError **error)
Waits for a specified I/O condition on socket.
P_LIB_API pboolean p_socket_is_closed(const PSocket *socket)
Checks whether a socket is closed.
P_LIB_API PSocketProtocol p_socket_get_protocol(const PSocket *socket)
Gets a socket data transfer protocol.
P_LIB_API pboolean p_socket_connect(PSocket *socket, PSocketAddress *address, PError **error)
Connects a socket to a given remote address.
struct PSocket_ PSocket
Socket opaque structure.
Definition psocket.h:191
PSocketProtocol_
Socket protocols specified by the IANA.
Definition psocket.h:162
@ P_SOCKET_PROTOCOL_DEFAULT
Default protocol.
Definition psocket.h:164
@ P_SOCKET_PROTOCOL_SCTP
SCTP protocol.
Definition psocket.h:167
@ P_SOCKET_PROTOCOL_UNKNOWN
Unknown protocol.
Definition psocket.h:163
@ P_SOCKET_PROTOCOL_UDP
UDP protocol.
Definition psocket.h:166
@ P_SOCKET_PROTOCOL_TCP
TCP protocol.
Definition psocket.h:165
P_LIB_API pboolean p_socket_is_connected(const PSocket *socket)
Checks whether a socket is connected.
P_LIB_API pssize p_socket_send_to(const PSocket *socket, PSocketAddress *address, const pchar *buffer, psize buflen, PError **error)
Sends data through a given socket to a given address.
PSocketType_
Socket types.
Definition psocket.h:171
@ P_SOCKET_TYPE_UNKNOWN
Unknown type.
Definition psocket.h:172
@ P_SOCKET_TYPE_SEQPACKET
Connection-less, reliable, datagram passing (i.e.
Definition psocket.h:175
@ P_SOCKET_TYPE_STREAM
Connection oritented, reliable, stream of bytes (i.e.
Definition psocket.h:173
@ P_SOCKET_TYPE_DATAGRAM
Connection-less, unreliable, datagram passing (i.e.
Definition psocket.h:174
P_LIB_API void p_socket_set_keepalive(PSocket *socket, pboolean keepalive)
Sets the socket SO_KEEPALIVE flag.
P_LIB_API pboolean p_socket_get_blocking(PSocket *socket)
Checks whether socket is used in a blocking mode.
P_LIB_API pboolean p_socket_bind(const PSocket *socket, PSocketAddress *address, pboolean allow_reuse, PError **error)
Binds a socket to a given local address.
P_LIB_API PSocketFamily p_socket_get_family(const PSocket *socket)
Gets a socket address family.
P_LIB_API pboolean p_socket_get_keepalive(const PSocket *socket)
Checks whether the SO_KEEPALIVE flag is enabled.
P_LIB_API pssize p_socket_send(const PSocket *socket, const pchar *buffer, psize buflen, PError **error)
Sends data through a given socket.
PSocketIOCondition_
Socket IO waiting (polling) conditions.
Definition psocket.h:185
@ P_SOCKET_IO_CONDITION_POLLOUT
Ready to write.
Definition psocket.h:187
@ P_SOCKET_IO_CONDITION_POLLIN
Ready to read.
Definition psocket.h:186
P_LIB_API void p_socket_set_listen_backlog(PSocket *socket, pint backlog)
Sets a socket listen backlog parameter.
PSocketDirection_
Socket direction for data operations.
Definition psocket.h:179
@ P_SOCKET_DIRECTION_SND
Send direction.
Definition psocket.h:180
@ P_SOCKET_DIRECTION_RCV
Receive direction.
Definition psocket.h:181
Socket address wrapper.
enum PSocketFamily_ PSocketFamily
Socket address family.
struct PSocketAddress_ PSocketAddress
Socket address opaque structure.
signed int pssize
Type for a platform independent signed size_t.
Definition ptypes.h:223
char pchar
Type for a char.
Definition ptypes.h:116
unsigned int psize
Type for a platform independent size_t.
Definition ptypes.h:224
int pint
Type for an int.
Definition ptypes.h:120
signed int pboolean
Type for a bool.
Definition ptypes.h:114