forked from neesenk/coro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoro.h
More file actions
71 lines (60 loc) · 2.22 KB
/
Copy pathcoro.h
File metadata and controls
71 lines (60 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Copyright (c) 2013, Zhiyong Liu <NeeseNK at gmail dot com>
* All rights reserved.
*/
#ifndef __CORO_H__
#define __CORO_H__
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <time.h>
#include <errno.h>
#include <poll.h>
#include <stdint.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct coro coro_t;
coro_t *coro_create(void (*start) (void *arg), void *arg);
int coro_init(size_t stack_size);
void coro_cleanup(void);
void coro_exit(void);
void coro_yield(void);
int coro_poll(int fd, int events, int timeout);
int coro_sleep(int usec);
int coro_make_pool(int n);
void coro_set_rcvtimeout(size_t timeout);
void coro_set_sndtimeout(size_t timeout);
int coro_accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
int coro_connect(int fd, const struct sockaddr *addr, int addrlen);
ssize_t coro_read(int fd, void *buf, size_t nbyte);
ssize_t coro_recv(int fd, void *buf, size_t nbyte, int flags);
ssize_t coro_read_fully(int fd, void *buf, size_t nbyte);
ssize_t coro_write(int fd, const void *buf, size_t nbyte);
ssize_t coro_send(int fd, const void *buf, size_t nbyte, int flags);
ssize_t coro_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
ssize_t coro_sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);
ssize_t coro_recvmsg(int fd, struct msghdr *msg, int flags);
ssize_t coro_sendmsg(int fd, const struct msghdr *msg, int flags);
//-------------------- for debug and test -------------
int _coro_ctx_run_count();
int _coro_ctx_active_count();
int _coro_ctx_total_count();
int _coro_ctx_cur_seq();
int _coro_seq_id();
//void schedule(); // will hang for ever
#define _coro_ctx(member) _coro_ctx_##member()
#define _coro(member) _coro_##member()
/* #define NDEBUG 1 */
#ifndef NDEBUG
#define PRINT_D(fmt,args...) printf("PRINT_D:%s:%d: "fmt"\n",__FUNCTION__,__LINE__, ##args) // debug out put
#else
#define PRINT_D(fmt,args...) (void)0
#endif
#ifdef __cplusplus
}
#endif
#endif /* !__CORO_H__ */