Blog
Community
Development
Documentation
CNDP
22.08.0
Toggle main menu visibility
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
24
extern
"C"
{
25
#endif
26
27
#define CSOCK_API __attribute__((visibility("default")))
28
32
#define __csock_unused __attribute__((__unused__))
33
34
enum
{
35
CSOCK_MAX_HOST_NAME_LENGTH
= 128,
36
CSOCK_MAX_SOCK_INFO_LENGTH
= 1024,
37
DEFAULT_CSOCK_RX_LEN
= 4096,
38
DEFAULT_CSOCK_TX_LEN
= 4096,
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
48
typedef
void
csock_t
;
49
58
typedef
void
*(
csock_client_fn_t
)(
csock_t
*c);
59
63
typedef
ssize_t(
csock_write_t
)(
csock_t
*c,
char
*data,
size_t
len);
64
68
typedef
ssize_t(
csock_read_t
)(
csock_t
*c,
char
*data,
size_t
len);
69
73
typedef
int(
csock_close_t
)(
csock_t
*c);
74
78
typedef
struct
csock_cfg
{
79
uint32_t
flags
;
80
char
*
host_addr
;
81
82
csock_client_fn_t
*
client_fn
;
83
csock_read_t
*
read_fn
;
84
csock_write_t
*
write_fn
;
85
csock_close_t
*
close_fn
;
86
}
csock_cfg_t
;
87
96
CSOCK_API
csock_t
*
csock_create
(
csock_cfg_t
*cfg);
97
106
CSOCK_API
void
csock_destroy
(
csock_t
*c);
107
116
CSOCK_API
int
csock_server_start
(
csock_t
*c);
117
126
CSOCK_API
csock_t
*
csock_accept
(
csock_t
*s);
127
141
CSOCK_API ssize_t
csock_read
(
csock_t
*c,
char
*data,
size_t
len);
142
155
CSOCK_API ssize_t
csock_write
(
csock_t
*c,
char
*data,
size_t
len);
156
165
CSOCK_API
int
csock_close
(
csock_t
*c);
166
175
CSOCK_API
struct
sockaddr *
csock_get_peer
(
csock_t
*c);
176
185
CSOCK_API
int
csock_eof
(
csock_t
*_c);
186
195
CSOCK_API
int
csock_get_fd
(
csock_t
*c);
196
207
CSOCK_API
int
csock_set_fd
(
csock_t
*_c,
int
fd);
208
217
CSOCK_API
int
csock_is_closed
(
csock_t
*c);
218
219
#ifdef __cplusplus
220
}
221
#endif
222
223
#endif
/* _CSOCK_H_ */
csock_t
void csock_t
Definition
csock.h:48
csock_eof
CSOCK_API int csock_eof(csock_t *_c)
csock_get_peer
CSOCK_API struct sockaddr * csock_get_peer(csock_t *c)
csock_accept
CSOCK_API csock_t * csock_accept(csock_t *s)
csock_write_t
ssize_t csock_write_t(csock_t *c, char *data, size_t len)
Definition
csock.h:63
CSOCK_IS_SERVER
@ CSOCK_IS_SERVER
Definition
csock.h:40
CSOCK_MAX_SOCK_INFO_LENGTH
@ CSOCK_MAX_SOCK_INFO_LENGTH
Definition
csock.h:36
DEFAULT_CSOCK_TX_LEN
@ DEFAULT_CSOCK_TX_LEN
Definition
csock.h:38
DEFAULT_CSOCK_RX_LEN
@ DEFAULT_CSOCK_RX_LEN
Definition
csock.h:37
CSOCK_MAX_HOST_NAME_LENGTH
@ CSOCK_MAX_HOST_NAME_LENGTH
Definition
csock.h:35
CSOCK_IS_CLIENT
@ CSOCK_IS_CLIENT
Definition
csock.h:41
CSOCK_NON_BLOCKING
@ CSOCK_NON_BLOCKING
Definition
csock.h:42
CSOCK_STDIO_TYPE
@ CSOCK_STDIO_TYPE
Definition
csock.h:45
CSOCK_GROUP_WRITE
@ CSOCK_GROUP_WRITE
Definition
csock.h:43
CSOCK_EOF
@ CSOCK_EOF
Definition
csock.h:44
csock_read
CSOCK_API ssize_t csock_read(csock_t *c, char *data, size_t len)
csock_write
CSOCK_API ssize_t csock_write(csock_t *c, char *data, size_t len)
csock_set_fd
CSOCK_API int csock_set_fd(csock_t *_c, int fd)
csock_server_start
CSOCK_API int csock_server_start(csock_t *c)
csock_client_fn_t
void * csock_client_fn_t(csock_t *c)
Definition
csock.h:58
csock_cfg_t
struct csock_cfg csock_cfg_t
csock_get_fd
CSOCK_API int csock_get_fd(csock_t *c)
csock_destroy
CSOCK_API void csock_destroy(csock_t *c)
csock_create
CSOCK_API csock_t * csock_create(csock_cfg_t *cfg)
csock_read_t
ssize_t csock_read_t(csock_t *c, char *data, size_t len)
Definition
csock.h:68
csock_close_t
int csock_close_t(csock_t *c)
Definition
csock.h:73
csock_close
CSOCK_API int csock_close(csock_t *c)
csock_is_closed
CSOCK_API int csock_is_closed(csock_t *c)
csock_cfg
Definition
csock.h:78
csock_cfg::client_fn
csock_client_fn_t * client_fn
Definition
csock.h:82
csock_cfg::flags
uint32_t flags
Definition
csock.h:79
csock_cfg::read_fn
csock_read_t * read_fn
Definition
csock.h:83
csock_cfg::host_addr
char * host_addr
Definition
csock.h:80
csock_cfg::write_fn
csock_write_t * write_fn
Definition
csock.h:84
csock_cfg::close_fn
csock_close_t * close_fn
Definition
csock.h:85
lib
usr
slib
csock
csock.h
Generated by
1.18.0