CNDP 22.08.0
Loading...
Searching...
No Matches
csock.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2020-2022 Intel Corporation
3 */
4
15
16#ifndef _CSOCK_H_
17#define _CSOCK_H_
18
19#include <stdint.h> // for uint32_t
20#include <stddef.h> // for size_t
21#include <sys/types.h> // for ssize_t
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#define CSOCK_API __attribute__((visibility("default")))
28
32#define __csock_unused __attribute__((__unused__))
33
34enum {
39
40 CSOCK_IS_SERVER = (1 << 0),
41 CSOCK_IS_CLIENT = (1 << 1),
42 CSOCK_NON_BLOCKING = (1 << 2),
43 CSOCK_GROUP_WRITE = (1 << 3),
44 CSOCK_EOF = (1 << 4),
45 CSOCK_STDIO_TYPE = (1 << 5),
46};
47
48typedef void csock_t;
49
58typedef void *(csock_client_fn_t)(csock_t *c);
59
63typedef ssize_t(csock_write_t)(csock_t *c, char *data, size_t len);
64
68typedef ssize_t(csock_read_t)(csock_t *c, char *data, size_t len);
69
73typedef int(csock_close_t)(csock_t *c);
74
87
97
106CSOCK_API void csock_destroy(csock_t *c);
107
116CSOCK_API int csock_server_start(csock_t *c);
117
127
141CSOCK_API ssize_t csock_read(csock_t *c, char *data, size_t len);
142
155CSOCK_API ssize_t csock_write(csock_t *c, char *data, size_t len);
156
165CSOCK_API int csock_close(csock_t *c);
166
175CSOCK_API struct sockaddr *csock_get_peer(csock_t *c);
176
185CSOCK_API int csock_eof(csock_t *_c);
186
195CSOCK_API int csock_get_fd(csock_t *c);
196
207CSOCK_API int csock_set_fd(csock_t *_c, int fd);
208
217CSOCK_API int csock_is_closed(csock_t *c);
218
219#ifdef __cplusplus
220}
221#endif
222
223#endif /* _CSOCK_H_ */
void csock_t
Definition csock.h:48
CSOCK_API int csock_eof(csock_t *_c)
CSOCK_API struct sockaddr * csock_get_peer(csock_t *c)
CSOCK_API csock_t * csock_accept(csock_t *s)
ssize_t csock_write_t(csock_t *c, char *data, size_t len)
Definition csock.h:63
@ CSOCK_IS_SERVER
Definition csock.h:40
@ CSOCK_MAX_SOCK_INFO_LENGTH
Definition csock.h:36
@ DEFAULT_CSOCK_TX_LEN
Definition csock.h:38
@ DEFAULT_CSOCK_RX_LEN
Definition csock.h:37
@ CSOCK_MAX_HOST_NAME_LENGTH
Definition csock.h:35
@ CSOCK_IS_CLIENT
Definition csock.h:41
@ CSOCK_NON_BLOCKING
Definition csock.h:42
@ CSOCK_STDIO_TYPE
Definition csock.h:45
@ CSOCK_GROUP_WRITE
Definition csock.h:43
@ CSOCK_EOF
Definition csock.h:44
CSOCK_API ssize_t csock_read(csock_t *c, char *data, size_t len)
CSOCK_API ssize_t csock_write(csock_t *c, char *data, size_t len)
CSOCK_API int csock_set_fd(csock_t *_c, int fd)
CSOCK_API int csock_server_start(csock_t *c)
void * csock_client_fn_t(csock_t *c)
Definition csock.h:58
struct csock_cfg csock_cfg_t
CSOCK_API int csock_get_fd(csock_t *c)
CSOCK_API void csock_destroy(csock_t *c)
CSOCK_API csock_t * csock_create(csock_cfg_t *cfg)
ssize_t csock_read_t(csock_t *c, char *data, size_t len)
Definition csock.h:68
int csock_close_t(csock_t *c)
Definition csock.h:73
CSOCK_API int csock_close(csock_t *c)
CSOCK_API int csock_is_closed(csock_t *c)
csock_client_fn_t * client_fn
Definition csock.h:82
uint32_t flags
Definition csock.h:79
csock_read_t * read_fn
Definition csock.h:83
char * host_addr
Definition csock.h:80
csock_write_t * write_fn
Definition csock.h:84
csock_close_t * close_fn
Definition csock.h:85