Link Here
|
|
|
1 |
--- lib/mosquitto.c |
2 |
+++ lib/mosquitto.c |
3 |
@@ -75,6 +75,14 @@ int mosquitto_lib_cleanup(void) |
4 |
return MOSQ_ERR_SUCCESS; |
5 |
} |
6 |
|
7 |
+int mosquitto_external_callbacks_set(struct mosquitto *mosq, size_t (*external_write_fnc)(void *buf, size_t count), size_t (*external_read_fnc)(void *buf, size_t count)) |
8 |
+{ |
9 |
+ if(mosq) { |
10 |
+ mosq->external_read_fnc = external_read_fnc; |
11 |
+ mosq->external_write_fnc = external_write_fnc; |
12 |
+ } |
13 |
+} |
14 |
+ |
15 |
struct mosquitto *mosquitto_new(const char *id, bool clean_start, void *userdata) |
16 |
{ |
17 |
struct mosquitto *mosq = NULL; |
18 |
--- lib/mosquitto.h |
19 |
+++ lib/mosquitto.h |
20 |
@@ -222,6 +222,7 @@ libmosq_EXPORT int mosquitto_lib_init(void); |
21 |
*/ |
22 |
libmosq_EXPORT int mosquitto_lib_cleanup(void); |
23 |
|
24 |
+libmosq_EXPORT int mosquitto_external_callbacks_set(struct mosquitto *mosq, size_t (*external_write_fnc)(void *buf, size_t count), size_t (*external_read_fnc)(void *buf, size_t count)); |
25 |
|
26 |
/* ====================================================================== |
27 |
* |
28 |
--- lib/mosquitto_internal.h |
29 |
+++ lib/mosquitto_internal.h |
30 |
@@ -346,6 +346,8 @@ struct mosquitto { |
31 |
#ifdef WITH_EPOLL |
32 |
uint32_t events; |
33 |
#endif |
34 |
+ size_t (*external_read_fnc)(void *buf, size_t count); |
35 |
+ size_t (*external_write_fnc)(void *buf, size_t count); |
36 |
}; |
37 |
|
38 |
#define STREMPTY(str) (str[0] == '\0') |
39 |
--- lib/net_mosq.c |
40 |
+++ lib/net_mosq.c |
41 |
@@ -824,6 +824,11 @@ int net__socket_connect_step3(struct mosquitto *mosq, const char *host) |
42 |
/* Create a socket and connect it to 'ip' on port 'port'. */ |
43 |
int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking) |
44 |
{ |
45 |
+ if(mosq->external_write_fnc) { |
46 |
+ mosq->sock = 777; |
47 |
+ return MOSQ_ERR_SUCCESS; |
48 |
+ } |
49 |
+ |
50 |
mosq_sock_t sock = INVALID_SOCKET; |
51 |
int rc, rc2; |
52 |
|
53 |
@@ -853,6 +858,10 @@ ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count) |
54 |
int err; |
55 |
#endif |
56 |
assert(mosq); |
57 |
+ |
58 |
+ if(mosq->external_read_fnc) |
59 |
+ return mosq->external_read_fnc(buf, count); |
60 |
+ |
61 |
errno = 0; |
62 |
#ifdef WITH_TLS |
63 |
if(mosq->ssl){ |
64 |
@@ -900,6 +909,9 @@ ssize_t net__write(struct mosquitto *mosq, void *buf, size_t count) |
65 |
#endif |
66 |
assert(mosq); |
67 |
|
68 |
+ if(mosq->external_write_fnc) |
69 |
+ return mosq->external_write_fnc(buf, count); |
70 |
+ |
71 |
errno = 0; |
72 |
#ifdef WITH_TLS |
73 |
if(mosq->ssl){ |
74 |
|
75 |
--- lib/mosquitto.c |
76 |
+++ lib/mosquitto.c |
77 |
@@ -75,7 +75,7 @@ int mosquitto_lib_cleanup(void) |
78 |
return MOSQ_ERR_SUCCESS; |
79 |
} |
80 |
|
81 |
-int mosquitto_external_callbacks_set(struct mosquitto *mosq, size_t (*external_write_fnc)(void *buf, size_t count), size_t (*external_read_fnc)(void *buf, size_t count)) |
82 |
+void mosquitto_external_callbacks_set(struct mosquitto *mosq, size_t (*external_write_fnc)(void *buf, size_t count), size_t (*external_read_fnc)(void *buf, size_t count)) |
83 |
{ |
84 |
if(mosq) { |
85 |
mosq->external_read_fnc = external_read_fnc; |
86 |
--- lib/mosquitto.h |
87 |
+++ lib/mosquitto.h |
88 |
@@ -222,7 +222,7 @@ libmosq_EXPORT int mosquitto_lib_init(void); |
89 |
*/ |
90 |
libmosq_EXPORT int mosquitto_lib_cleanup(void); |
91 |
|
92 |
-libmosq_EXPORT int mosquitto_external_callbacks_set(struct mosquitto *mosq, size_t (*external_write_fnc)(void *buf, size_t count), size_t (*external_read_fnc)(void *buf, size_t count)); |
93 |
+libmosq_EXPORT void mosquitto_external_callbacks_set(struct mosquitto *mosq, size_t (*external_write_fnc)(void *buf, size_t count), size_t (*external_read_fnc)(void *buf, size_t count)); |
94 |
|
95 |
/* ====================================================================== |
96 |
* |