-
Notifications
You must be signed in to change notification settings - Fork 6
/
atp.h
68 lines (61 loc) · 2.63 KB
/
atp.h
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
/*
* Calvin Neo
* Copyright (C) 2017 Calvin Neo <calvinneo@calvinneo.com>
* https://github.com/CalvinNeo/ATP
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include <stdint.h>
#include <sys/types.h> // ssize_t
#include "atp_common.h"
// API of ATP
#ifdef __cplusplus
extern "C" {
#endif
enum atp_api_options{
ATP_API_SACKOPT,
ATP_API_SOCKID,
ATP_API_STATUS,
ATP_API_WRITABLE,
ATP_API_READABLE,
ATP_API_EOF,
ATP_API_REUSEPORT,
ATP_API_SENDINGSTATUS
};
atp_context * atp_create_context();
atp_socket * atp_create_socket(atp_context * context);
atp_socket * atp_fork_socket(atp_socket * origin); // Fork the socket of exactly the same type
atp_socket * atp_fork_basic_socket(atp_socket * origin); // Fork the socket to get a `ATPSocket *`
atp_result atp_listen(atp_socket * socket, uint16_t port);
// set callback ATP_CALL_ON_ESTABLISHED before calling
atp_result atp_async_connect(atp_socket * socket, const struct sockaddr * to, socklen_t tolen);
atp_result atp_async_accept(atp_socket * socket, const struct sockaddr * to, socklen_t tolen);
atp_result atp_async_write(atp_socket * socket, void * buf, size_t length);
atp_result atp_send_packet(atp_socket * socket, void * buf, size_t length);
atp_result atp_send_oob(atp_socket * socket, void * buf, size_t length, uint32_t timeout);
atp_result atp_process_udp(atp_context * context, int sockfd, const char * buf, size_t len, const struct sockaddr * to, socklen_t tolen);
atp_result atp_timer_event(atp_context * context, uint64_t interval);
atp_result atp_async_close(atp_socket * socket);
atp_result atp_destroy(atp_socket * socket);
void atp_set_callback(atp_socket * socket, int callback_type, atp_callback_func * proc);
atp_result atp_eof(atp_socket * socket);
bool atp_destroyed(atp_socket * socket);
int atp_getfd(atp_socket * socket);
void atp_set_long(atp_socket * socket, size_t option, size_t value);
size_t atp_get_long(atp_socket * socket, size_t option);
#ifdef __cplusplus
}
#endif