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 | #ifndef _NET_MOSQ_H_
|
30 | #define _NET_MOSQ_H_
|
31 |
|
32 | #ifndef WIN32
|
33 | #include <unistd.h>
|
34 | #else
|
35 | #include <winsock2.h>
|
36 | typedef int ssize_t;
|
37 | #endif
|
38 |
|
39 | #include "mosquitto_internal.h"
|
40 | #include "mosquitto.h"
|
41 |
|
42 | #ifdef WITH_BROKER
|
43 | struct mosquitto_db;
|
44 | #endif
|
45 |
|
46 | #ifdef WIN32
|
47 | # define COMPAT_CLOSE(a) closesocket(a)
|
48 | # define COMPAT_ECONNRESET WSAECONNRESET
|
49 | # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK
|
50 | #else
|
51 | # define COMPAT_CLOSE(a) close(a)
|
52 | # define COMPAT_ECONNRESET ECONNRESET
|
53 | # define COMPAT_EWOULDBLOCK EWOULDBLOCK
|
54 | #endif
|
55 |
|
56 | #ifndef WIN32
|
57 | #else
|
58 | #endif
|
59 |
|
60 |
|
61 | #ifndef INVALID_SOCKET
|
62 | #define INVALID_SOCKET -1
|
63 | #endif
|
64 |
|
65 |
|
66 | #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8)
|
67 | #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF)
|
68 |
|
69 | void _mosquitto_net_init(void);
|
70 | void _mosquitto_net_cleanup(void);
|
71 |
|
72 | void _mosquitto_packet_cleanup(struct _mosquitto_packet *packet);
|
73 | int _mosquitto_packet_queue(struct mosquitto *mosq, struct _mosquitto_packet *packet);
|
74 | int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking);
|
75 | int _mosquitto_socket_close(struct mosquitto *mosq);
|
76 | int _mosquitto_try_connect(const char *host, uint16_t port, int *sock, const char *bind_address, bool blocking);
|
77 | int _mosquitto_socket_nonblock(int sock);
|
78 | int _mosquitto_socketpair(int *sp1, int *sp2);
|
79 |
|
80 | int _mosquitto_read_byte(struct _mosquitto_packet *packet, uint8_t *byte);
|
81 | int _mosquitto_read_bytes(struct _mosquitto_packet *packet, void *bytes, uint32_t count);
|
82 | int _mosquitto_read_string(struct _mosquitto_packet *packet, char **str);
|
83 | int _mosquitto_read_uint16(struct _mosquitto_packet *packet, uint16_t *word);
|
84 |
|
85 | void _mosquitto_write_byte(struct _mosquitto_packet *packet, uint8_t byte);
|
86 | void _mosquitto_write_bytes(struct _mosquitto_packet *packet, const void *bytes, uint32_t count);
|
87 | void _mosquitto_write_string(struct _mosquitto_packet *packet, const char *str, uint16_t length);
|
88 | void _mosquitto_write_uint16(struct _mosquitto_packet *packet, uint16_t word);
|
89 |
|
90 | ssize_t _mosquitto_net_read(struct mosquitto *mosq, void *buf, size_t count);
|
91 | ssize_t _mosquitto_net_write(struct mosquitto *mosq, void *buf, size_t count);
|
92 |
|
93 | int _mosquitto_packet_write(struct mosquitto *mosq);
|
94 | #ifdef WITH_BROKER
|
95 | int _mosquitto_packet_read(struct mosquitto_db *db, struct mosquitto *mosq);
|
96 | #else
|
97 | int _mosquitto_packet_read(struct mosquitto *mosq);
|
98 | #endif
|
99 |
|
100 | #ifdef WITH_TLS
|
101 | int _mosquitto_socket_apply_tls(struct mosquitto *mosq);
|
102 | #endif
|
103 |
|
104 | #endif
|