|
@@ -7,18 +7,23 @@
|
|
|
#include "list.h"
|
|
|
#include "bus_internal.h"
|
|
|
|
|
|
-#define BUS_RESULT_DATA 1 // ==BUS_TYPE_PACKET, callback: callback.on_pkt, no use
|
|
|
-#define BUS_RESULT_INFO 2 // ==BUS_TYPE_INFO, callback: callback.on_inf
|
|
|
-#define BUS_RESULT_EVENT 3 // ==BUS_TYPE_EVENT, callback: callback.on_evt , no use
|
|
|
-#define BUS_RESULT_SYSTEM 4 // ==BUS_TYPE_SYSTEM, callback: callback.on_sys
|
|
|
-#define BUS_RESULT_MSG 5 // send package msg, callback: callback.on_msg
|
|
|
+#include <winpr/file.h>
|
|
|
+#include <winpr/pipe.h>
|
|
|
+#include <winpr/synch.h>
|
|
|
+#include <winpr/string.h>
|
|
|
+
|
|
|
+#define BUS_RESULT_DATA 1 // ==BUS_TYPE_PACKET, callback: callback.on_pkt, no use
|
|
|
+#define BUS_RESULT_INFO 2 // ==BUS_TYPE_INFO, callback: callback.on_inf
|
|
|
+#define BUS_RESULT_EVENT 3 // ==BUS_TYPE_EVENT, callback: callback.on_evt , no use
|
|
|
+#define BUS_RESULT_SYSTEM 4 // ==BUS_TYPE_SYSTEM, callback: callback.on_sys
|
|
|
+#define BUS_RESULT_MSG 5 // send package msg, callback: callback.on_msg
|
|
|
#define BUS_RESULT_UNKNOWN 6
|
|
|
|
|
|
typedef struct msg_t {
|
|
|
struct list_head entry;
|
|
|
int type;
|
|
|
int nparam;
|
|
|
- int *params;
|
|
|
+ int* params;
|
|
|
HANDLE evt;
|
|
|
int evt_result;
|
|
|
}msg_t;
|
|
@@ -30,7 +35,7 @@ struct bus_endpt_t {
|
|
|
HANDLE pipe_handle;
|
|
|
SOCKET sock_handle;
|
|
|
};
|
|
|
- char *url;
|
|
|
+ char* url;
|
|
|
bus_endpt_callback callback;
|
|
|
struct list_head msg_list;
|
|
|
spinlock_t msg_lock;
|
|
@@ -40,11 +45,11 @@ struct bus_endpt_t {
|
|
|
OVERLAPPED rx_overlapped;
|
|
|
int rx_pending;
|
|
|
int rx_pending_pkt_len;
|
|
|
- iobuffer_queue_t *rx_buf_queue;
|
|
|
+ iobuffer_queue_t* rx_buf_queue;
|
|
|
volatile int quit_flag;
|
|
|
};
|
|
|
|
|
|
-static void free_msg(msg_t *msg)
|
|
|
+static void free_msg(msg_t* msg)
|
|
|
{
|
|
|
free(msg->params);
|
|
|
free(msg);
|
|
@@ -67,7 +72,7 @@ static int to_result(int pkt_type)
|
|
|
return BUS_RESULT_UNKNOWN;
|
|
|
}
|
|
|
|
|
|
-static HANDLE create_pipe_handle(const char *name)
|
|
|
+static HANDLE create_pipe_handle(const char* name)
|
|
|
{
|
|
|
char tmp[MAX_PATH];
|
|
|
HANDLE pipe = INVALID_HANDLE_VALUE;
|
|
@@ -75,10 +80,10 @@ static HANDLE create_pipe_handle(const char *name)
|
|
|
sprintf(tmp, "\\\\.\\pipe\\%s", name);
|
|
|
|
|
|
for (;;) {
|
|
|
- pipe = CreateFileA(tmp,
|
|
|
- GENERIC_READ|GENERIC_WRITE,
|
|
|
- 0,
|
|
|
- NULL,
|
|
|
+ pipe = CreateFileA(tmp,
|
|
|
+ GENERIC_READ | GENERIC_WRITE,
|
|
|
+ 0,
|
|
|
+ NULL,
|
|
|
OPEN_EXISTING,
|
|
|
FILE_FLAG_OVERLAPPED,
|
|
|
NULL);
|
|
@@ -94,7 +99,7 @@ static HANDLE create_pipe_handle(const char *name)
|
|
|
return pipe;
|
|
|
}
|
|
|
|
|
|
-static SOCKET create_socket_handle(const char *ip, int port)
|
|
|
+static SOCKET create_socket_handle(const char* ip, int port)
|
|
|
{
|
|
|
SOCKET fd;
|
|
|
struct sockaddr_in addr;
|
|
@@ -117,7 +122,7 @@ static SOCKET create_socket_handle(const char *ip, int port)
|
|
|
addr.sin_port = htons(port);
|
|
|
addr.sin_addr.s_addr = inet_addr(ip);
|
|
|
|
|
|
- if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) != 0) {
|
|
|
+ if (connect(fd, (struct sockaddr*) & addr, sizeof(addr)) != 0) {
|
|
|
if (WSAGetLastError() == WSAEWOULDBLOCK) {
|
|
|
fd_set wr_set, ex_set;
|
|
|
FD_ZERO(&wr_set);
|
|
@@ -137,7 +142,7 @@ static SOCKET create_socket_handle(const char *ip, int port)
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int tcp_send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
+static int tcp_send_buf(bus_endpt_t* endpt, const char* buf, int n)
|
|
|
{
|
|
|
DWORD left = n;
|
|
|
DWORD offset = 0;
|
|
@@ -150,7 +155,7 @@ static int tcp_send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
memset(&overlapped, 0, sizeof(overlapped));
|
|
|
overlapped.hEvent = endpt->tx_evt;
|
|
|
ResetEvent(endpt->tx_evt);
|
|
|
- wsabuf.buf = (char*)buf+offset;
|
|
|
+ wsabuf.buf = (char*)buf + offset;
|
|
|
wsabuf.len = left;
|
|
|
ret = WSASend(endpt->sock_handle, &wsabuf, 1, &dwBytesTransfer, 0, &overlapped, NULL) == 0;
|
|
|
if (!ret && WSAGetLastError() == WSA_IO_PENDING) {
|
|
@@ -160,7 +165,8 @@ static int tcp_send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
if (ret && dwBytesTransfer) {
|
|
|
offset += dwBytesTransfer;
|
|
|
left -= dwBytesTransfer;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
@@ -169,7 +175,7 @@ static int tcp_send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
|
|
|
}
|
|
|
|
|
|
-static int pipe_send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
+static int pipe_send_buf(bus_endpt_t* endpt, const char* buf, int n)
|
|
|
{
|
|
|
DWORD left = n;
|
|
|
DWORD offset = 0;
|
|
@@ -181,14 +187,15 @@ static int pipe_send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
memset(&overlapped, 0, sizeof(overlapped));
|
|
|
overlapped.hEvent = endpt->tx_evt;
|
|
|
ResetEvent(endpt->tx_evt);
|
|
|
- ret = WriteFile(endpt->pipe_handle, buf+offset, left, &dwBytesTransfer, &overlapped);
|
|
|
+ ret = WriteFile(endpt->pipe_handle, buf + offset, left, &dwBytesTransfer, &overlapped);
|
|
|
if (!ret && GetLastError() == ERROR_IO_PENDING) {
|
|
|
ret = GetOverlappedResult(endpt->pipe_handle, &overlapped, &dwBytesTransfer, TRUE);
|
|
|
}
|
|
|
if (ret && dwBytesTransfer) {
|
|
|
offset += dwBytesTransfer;
|
|
|
left -= dwBytesTransfer;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
@@ -196,18 +203,20 @@ static int pipe_send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int send_buf(bus_endpt_t *endpt, const char *buf, int n)
|
|
|
+static int send_buf(bus_endpt_t* endpt, const char* buf, int n)
|
|
|
{
|
|
|
if (endpt->type == TYPE_PIPE) {
|
|
|
return pipe_send_buf(endpt, buf, n);
|
|
|
- } else if (endpt->type == TYPE_TCP) {
|
|
|
+ }
|
|
|
+ else if (endpt->type == TYPE_TCP) {
|
|
|
return tcp_send_buf(endpt, buf, n);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static int send_pkt_raw(bus_endpt_t *endpt, iobuffer_t *pkt)
|
|
|
+static int send_pkt_raw(bus_endpt_t* endpt, iobuffer_t* pkt)
|
|
|
{
|
|
|
int pkt_len = iobuffer_get_length(pkt);
|
|
|
int rc;
|
|
@@ -218,7 +227,7 @@ static int send_pkt_raw(bus_endpt_t *endpt, iobuffer_t *pkt)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-static int pipe_recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
+static int pipe_recv_buf(bus_endpt_t* endpt, char* buf, DWORD n)
|
|
|
{
|
|
|
DWORD left = n;
|
|
|
DWORD offset = 0;
|
|
@@ -230,14 +239,15 @@ static int pipe_recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
memset(&overlapped, 0, sizeof(overlapped));
|
|
|
overlapped.hEvent = endpt->rx_evt;
|
|
|
ResetEvent(overlapped.hEvent);
|
|
|
- ret = ReadFile(endpt->pipe_handle, buf+offset, left, &dwBytesTransfer, &overlapped);
|
|
|
+ ret = ReadFile(endpt->pipe_handle, buf + offset, left, &dwBytesTransfer, &overlapped);
|
|
|
if (!ret && GetLastError() == ERROR_IO_PENDING) {
|
|
|
ret = GetOverlappedResult(endpt->pipe_handle, &overlapped, &dwBytesTransfer, TRUE);
|
|
|
}
|
|
|
if (ret && dwBytesTransfer) {
|
|
|
offset += dwBytesTransfer;
|
|
|
left -= dwBytesTransfer;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
@@ -245,7 +255,7 @@ static int pipe_recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int tcp_recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
+static int tcp_recv_buf(bus_endpt_t* endpt, char* buf, DWORD n)
|
|
|
{
|
|
|
DWORD left = n;
|
|
|
DWORD offset = 0;
|
|
@@ -258,7 +268,7 @@ static int tcp_recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
OVERLAPPED overlapped;
|
|
|
memset(&overlapped, 0, sizeof(overlapped));
|
|
|
overlapped.hEvent = endpt->rx_evt;
|
|
|
- wsabuf.buf = buf +offset;
|
|
|
+ wsabuf.buf = buf + offset;
|
|
|
wsabuf.len = left;
|
|
|
ResetEvent(overlapped.hEvent);
|
|
|
ret = WSARecv(endpt->sock_handle, &wsabuf, 1, &dwBytesTransfer, &dwFlags, &overlapped, NULL) == 0;
|
|
@@ -268,7 +278,8 @@ static int tcp_recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
if (ret && dwBytesTransfer) {
|
|
|
offset += dwBytesTransfer;
|
|
|
left -= dwBytesTransfer;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
@@ -276,18 +287,20 @@ static int tcp_recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int recv_buf(bus_endpt_t *endpt, char *buf, DWORD n)
|
|
|
+static int recv_buf(bus_endpt_t* endpt, char* buf, DWORD n)
|
|
|
{
|
|
|
if (endpt->type == TYPE_PIPE) {
|
|
|
return pipe_recv_buf(endpt, buf, n);
|
|
|
- } else if (endpt->type == TYPE_TCP) {
|
|
|
+ }
|
|
|
+ else if (endpt->type == TYPE_TCP) {
|
|
|
return tcp_recv_buf(endpt, buf, n);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static int recv_pkt_raw(bus_endpt_t *endpt, iobuffer_t **pkt)
|
|
|
+static int recv_pkt_raw(bus_endpt_t* endpt, iobuffer_t** pkt)
|
|
|
{
|
|
|
int pkt_len;
|
|
|
int rc = -1;
|
|
@@ -308,12 +321,12 @@ static int recv_pkt_raw(bus_endpt_t *endpt, iobuffer_t **pkt)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-static int start_read_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
+static int start_read_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
|
|
|
{
|
|
|
DWORD dwBytesTransferred;
|
|
|
BOOL ret;
|
|
|
int rc = 0;
|
|
|
- iobuffer_t *pkt = NULL;
|
|
|
+ iobuffer_t* pkt = NULL;
|
|
|
|
|
|
*p_pkt = NULL;
|
|
|
|
|
@@ -322,24 +335,26 @@ static int start_read_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
endpt->rx_overlapped.hEvent = endpt->rx_evt;
|
|
|
|
|
|
if (endpt->type == TYPE_PIPE) {
|
|
|
- ret = ReadFile(endpt->pipe_handle,
|
|
|
- &endpt->rx_pending_pkt_len,
|
|
|
- 4,
|
|
|
- &dwBytesTransferred,
|
|
|
+ ret = ReadFile(endpt->pipe_handle,
|
|
|
+ &endpt->rx_pending_pkt_len,
|
|
|
+ 4,
|
|
|
+ &dwBytesTransferred,
|
|
|
&endpt->rx_overlapped);
|
|
|
- } else if (endpt->type == TYPE_TCP) {
|
|
|
+ }
|
|
|
+ else if (endpt->type == TYPE_TCP) {
|
|
|
DWORD dwFlags = 0;
|
|
|
WSABUF wsabuf;
|
|
|
wsabuf.buf = (char*)&endpt->rx_pending_pkt_len;
|
|
|
wsabuf.len = 4;
|
|
|
- ret = WSARecv(endpt->sock_handle,
|
|
|
- &wsabuf,
|
|
|
- 1,
|
|
|
- &dwBytesTransferred,
|
|
|
- &dwFlags,
|
|
|
- &endpt->rx_overlapped,
|
|
|
+ ret = WSARecv(endpt->sock_handle,
|
|
|
+ &wsabuf,
|
|
|
+ 1,
|
|
|
+ &dwBytesTransferred,
|
|
|
+ &dwFlags,
|
|
|
+ &endpt->rx_overlapped,
|
|
|
NULL) == 0;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -347,15 +362,14 @@ static int start_read_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
if (dwBytesTransferred == 0)
|
|
|
return -1;
|
|
|
if (dwBytesTransferred < 4) {
|
|
|
- rc = recv_buf(endpt, (char*)&endpt->rx_pending_pkt_len+dwBytesTransferred, 4-dwBytesTransferred);
|
|
|
+ rc = recv_buf(endpt, (char*)&endpt->rx_pending_pkt_len + dwBytesTransferred, 4 - dwBytesTransferred);
|
|
|
if (rc < 0)
|
|
|
return rc;
|
|
|
}
|
|
|
pkt = iobuffer_create(0, endpt->rx_pending_pkt_len);
|
|
|
if (endpt->rx_pending_pkt_len > 0) {
|
|
|
rc = recv_buf(endpt, iobuffer_data(pkt, 0), endpt->rx_pending_pkt_len);
|
|
|
- if (rc < 0)
|
|
|
- {
|
|
|
+ if (rc < 0) {
|
|
|
iobuffer_destroy(pkt);
|
|
|
return rc;
|
|
|
}
|
|
@@ -363,10 +377,12 @@ static int start_read_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
iobuffer_push_count(pkt, endpt->rx_pending_pkt_len);
|
|
|
}
|
|
|
*p_pkt = pkt;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
if (WSAGetLastError() == WSA_IO_PENDING) {
|
|
|
endpt->rx_pending = 1;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
@@ -374,16 +390,17 @@ static int start_read_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int read_left_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
+static int read_left_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
|
|
|
{
|
|
|
BOOL ret;
|
|
|
int rc;
|
|
|
DWORD dwBytesTransferred;
|
|
|
- iobuffer_t *pkt = NULL;
|
|
|
+ iobuffer_t* pkt = NULL;
|
|
|
|
|
|
if (endpt->type == TYPE_PIPE) {
|
|
|
ret = GetOverlappedResult(endpt->pipe_handle, &endpt->rx_overlapped, &dwBytesTransferred, TRUE);
|
|
|
- } else if (endpt->type == TYPE_TCP) {
|
|
|
+ }
|
|
|
+ else if (endpt->type == TYPE_TCP) {
|
|
|
DWORD dwFlags = 0;
|
|
|
ret = WSAGetOverlappedResult(endpt->sock_handle, &endpt->rx_overlapped, &dwBytesTransferred, TRUE, &dwFlags);
|
|
|
}
|
|
@@ -393,14 +410,13 @@ static int read_left_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
return -1;
|
|
|
}
|
|
|
if (dwBytesTransferred < 4) {
|
|
|
- rc = recv_buf(endpt, (char*)&endpt->rx_pending_pkt_len+dwBytesTransferred, 4-dwBytesTransferred);
|
|
|
+ rc = recv_buf(endpt, (char*)&endpt->rx_pending_pkt_len + dwBytesTransferred, 4 - dwBytesTransferred);
|
|
|
if (rc < 0)
|
|
|
return rc;
|
|
|
}
|
|
|
pkt = iobuffer_create(-1, endpt->rx_pending_pkt_len);
|
|
|
rc = recv_buf(endpt, iobuffer_data(pkt, 0), endpt->rx_pending_pkt_len);
|
|
|
- if (rc < 0)
|
|
|
- {
|
|
|
+ if (rc < 0) {
|
|
|
iobuffer_destroy(pkt);
|
|
|
return rc;
|
|
|
}
|
|
@@ -411,7 +427,7 @@ static int read_left_pkt(bus_endpt_t *endpt, iobuffer_t **p_pkt)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static int append_rx_pkt(bus_endpt_t *endpt, iobuffer_t *pkt)
|
|
|
+static int append_rx_pkt(bus_endpt_t* endpt, iobuffer_t* pkt)
|
|
|
{
|
|
|
int type;
|
|
|
int read_state;
|
|
@@ -422,20 +438,21 @@ static int append_rx_pkt(bus_endpt_t *endpt, iobuffer_t *pkt)
|
|
|
if (type == BUS_TYPE_PACKET || type == BUS_TYPE_INFO || type == BUS_TYPE_EVENT || type == BUS_TYPE_SYSTEM) {
|
|
|
iobuffer_queue_enqueue(endpt->rx_buf_queue, pkt);
|
|
|
return 1;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_create(const char *url, int epid, const bus_endpt_callback *callback, bus_endpt_t **p_endpt)
|
|
|
+TOOLKIT_API int bus_endpt_create(const char* url, int epid, const bus_endpt_callback* callback, bus_endpt_t** p_endpt)
|
|
|
{
|
|
|
- bus_endpt_t *endpt = NULL;
|
|
|
- char *tmp_url;
|
|
|
+ bus_endpt_t* endpt = NULL;
|
|
|
+ char* tmp_url;
|
|
|
url_fields uf;
|
|
|
int rc;
|
|
|
int v;
|
|
|
- iobuffer_t *buf = NULL;
|
|
|
- iobuffer_t *ans_buf = NULL;
|
|
|
+ iobuffer_t* buf = NULL;
|
|
|
+ iobuffer_t* ans_buf = NULL;
|
|
|
|
|
|
if (!url)
|
|
|
return -1;
|
|
@@ -456,12 +473,14 @@ TOOLKIT_API int bus_endpt_create(const char *url, int epid, const bus_endpt_call
|
|
|
endpt->sock_handle = create_socket_handle(uf.host, uf.port);
|
|
|
if (endpt->sock_handle == INVALID_SOCKET)
|
|
|
goto on_error;
|
|
|
- } else if (_stricmp(uf.scheme, "pipe") == 0) {
|
|
|
+ }
|
|
|
+ else if (_stricmp(uf.scheme, "pipe") == 0) {
|
|
|
endpt->type = TYPE_PIPE;
|
|
|
endpt->pipe_handle = create_pipe_handle(uf.host);
|
|
|
if (endpt->pipe_handle == INVALID_HANDLE_VALUE)
|
|
|
goto on_error;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
goto on_error;
|
|
|
}
|
|
|
|
|
@@ -489,7 +508,7 @@ TOOLKIT_API int bus_endpt_create(const char *url, int epid, const bus_endpt_call
|
|
|
}
|
|
|
iobuffer_read(ans_buf, IOBUF_T_I4, &v, 0);
|
|
|
iobuffer_read(ans_buf, IOBUF_T_I4, &rc, 0);
|
|
|
- if (rc != 0)
|
|
|
+ if (rc != 0)
|
|
|
goto on_error;
|
|
|
|
|
|
url_free_fields(&uf);
|
|
@@ -505,7 +524,8 @@ TOOLKIT_API int bus_endpt_create(const char *url, int epid, const bus_endpt_call
|
|
|
on_error:
|
|
|
if (endpt->type == TYPE_TCP) {
|
|
|
closesocket(endpt->sock_handle);
|
|
|
- } else if (endpt->type == TYPE_PIPE) {
|
|
|
+ }
|
|
|
+ else if (endpt->type == TYPE_PIPE) {
|
|
|
CloseHandle(endpt->pipe_handle);
|
|
|
}
|
|
|
if (endpt->msg_sem)
|
|
@@ -527,11 +547,11 @@ on_error:
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API void bus_endpt_destroy(bus_endpt_t *endpt)
|
|
|
+TOOLKIT_API void bus_endpt_destroy(bus_endpt_t* endpt)
|
|
|
{
|
|
|
int rc = -1;
|
|
|
- iobuffer_t *buf = NULL;
|
|
|
- iobuffer_t *ans_buf = NULL;
|
|
|
+ iobuffer_t* buf = NULL;
|
|
|
+ iobuffer_t* ans_buf = NULL;
|
|
|
int v;
|
|
|
|
|
|
assert(endpt);
|
|
@@ -550,7 +570,7 @@ TOOLKIT_API void bus_endpt_destroy(bus_endpt_t *endpt)
|
|
|
iobuffer_read(ans_buf, IOBUF_T_I4, &v, 0);
|
|
|
iobuffer_read(ans_buf, IOBUF_T_I4, &rc, 0);
|
|
|
{
|
|
|
- msg_t *msg, *t;
|
|
|
+ msg_t* msg, * t;
|
|
|
list_for_each_entry_safe(msg, t, &endpt->msg_list, msg_t, entry) {
|
|
|
list_del(&msg->entry);
|
|
|
if (msg->evt)
|
|
@@ -567,7 +587,8 @@ on_error:
|
|
|
iobuffer_destroy(ans_buf);
|
|
|
if (endpt->type == TYPE_TCP) {
|
|
|
closesocket(endpt->sock_handle);
|
|
|
- } else if (endpt->type == TYPE_PIPE) {
|
|
|
+ }
|
|
|
+ else if (endpt->type == TYPE_PIPE) {
|
|
|
CloseHandle(endpt->pipe_handle);
|
|
|
}
|
|
|
if (endpt->msg_sem)
|
|
@@ -586,9 +607,9 @@ on_error:
|
|
|
// 1 : recv ok
|
|
|
// 0 : time out
|
|
|
// <0 : error
|
|
|
-static int bus_endpt_poll_internal(bus_endpt_t *endpt, int *result, int timeout)
|
|
|
+static int bus_endpt_poll_internal(bus_endpt_t* endpt, int* result, int timeout)
|
|
|
{
|
|
|
- iobuffer_t *pkt = NULL;
|
|
|
+ iobuffer_t* pkt = NULL;
|
|
|
int rc;
|
|
|
BOOL ret;
|
|
|
|
|
@@ -596,7 +617,7 @@ static int bus_endpt_poll_internal(bus_endpt_t *endpt, int *result, int timeout)
|
|
|
|
|
|
// peek first packge type
|
|
|
if (iobuffer_queue_count(endpt->rx_buf_queue) > 0) {
|
|
|
- iobuffer_t *pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
+ iobuffer_t* pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
int pkt_type;
|
|
|
int read_state = iobuffer_get_read_state(pkt);
|
|
|
iobuffer_read(pkt, IOBUF_T_I4, &pkt_type, NULL);
|
|
@@ -621,23 +642,26 @@ static int bus_endpt_poll_internal(bus_endpt_t *endpt, int *result, int timeout)
|
|
|
iobuffer_destroy(pkt);
|
|
|
return -1;
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
OutputDebugStringA("pending\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// if receive is pending, wait for send or receive complete event
|
|
|
if (!pkt) {
|
|
|
- HANDLE hs[] = {endpt->msg_sem, endpt->rx_evt };
|
|
|
+ HANDLE hs[] = { endpt->msg_sem, endpt->rx_evt };
|
|
|
ret = WaitForMultipleObjects(array_size(hs), &hs[0], FALSE, (DWORD)timeout);
|
|
|
if (ret == WAIT_TIMEOUT) {
|
|
|
return 0;
|
|
|
- } else if (ret == WAIT_OBJECT_0) {
|
|
|
+ }
|
|
|
+ else if (ret == WAIT_OBJECT_0) {
|
|
|
*result = BUS_RESULT_MSG; // indicate send package event
|
|
|
return 1;
|
|
|
- } else if (ret == WAIT_OBJECT_0 + 1) {
|
|
|
+ }
|
|
|
+ else if (ret == WAIT_OBJECT_0 + 1) {
|
|
|
rc = read_left_pkt(endpt, &pkt);
|
|
|
- if (rc <0)
|
|
|
+ if (rc < 0)
|
|
|
return rc;
|
|
|
|
|
|
if (pkt) {
|
|
@@ -648,11 +672,12 @@ static int bus_endpt_poll_internal(bus_endpt_t *endpt, int *result, int timeout)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
OutputDebugStringA("pkt has readed\n");
|
|
|
}
|
|
|
|
|
|
- if (pkt) {
|
|
|
+ if (pkt) {
|
|
|
int type;
|
|
|
int read_state = iobuffer_get_read_state(pkt);
|
|
|
iobuffer_read(pkt, IOBUF_T_I4, &type, 0);
|
|
@@ -662,17 +687,18 @@ static int bus_endpt_poll_internal(bus_endpt_t *endpt, int *result, int timeout)
|
|
|
OutputDebugStringA("bug: unknown pkt type!\n");
|
|
|
return -1;
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-static int recv_until(bus_endpt_t *endpt, int type, iobuffer_t **p_ansbuf)
|
|
|
+static int recv_until(bus_endpt_t* endpt, int type, iobuffer_t** p_ansbuf)
|
|
|
{
|
|
|
int rc;
|
|
|
- iobuffer_t *ans_pkt = NULL;
|
|
|
+ iobuffer_t* ans_pkt = NULL;
|
|
|
int ans_type;
|
|
|
|
|
|
for (;;) {
|
|
@@ -698,12 +724,14 @@ static int recv_until(bus_endpt_t *endpt, int type, iobuffer_t **p_ansbuf)
|
|
|
if (ans_type == type) {
|
|
|
*p_ansbuf = ans_pkt;
|
|
|
break;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
rc = append_rx_pkt(endpt, ans_pkt);
|
|
|
if (rc < 0) {
|
|
|
iobuffer_destroy(ans_pkt);
|
|
|
break;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
ans_pkt = NULL;
|
|
|
}
|
|
|
}
|
|
@@ -713,16 +741,16 @@ static int recv_until(bus_endpt_t *endpt, int type, iobuffer_t **p_ansbuf)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-static int recv_until_result(bus_endpt_t *endpt, int *p_result)
|
|
|
+static int recv_until_result(bus_endpt_t* endpt, int* p_result)
|
|
|
{
|
|
|
int rc;
|
|
|
- iobuffer_t *ans_pkt = NULL;
|
|
|
+ iobuffer_t* ans_pkt = NULL;
|
|
|
int type, error;
|
|
|
|
|
|
rc = recv_until(endpt, BUS_TYPE_ERROR, &ans_pkt);
|
|
|
if (rc < 0)
|
|
|
return rc;
|
|
|
-
|
|
|
+
|
|
|
iobuffer_read(ans_pkt, IOBUF_T_I4, &type, 0);
|
|
|
iobuffer_read(ans_pkt, IOBUF_T_I4, &error, 0);
|
|
|
iobuffer_destroy(ans_pkt);
|
|
@@ -732,10 +760,10 @@ static int recv_until_result(bus_endpt_t *endpt, int *p_result)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-static int recv_until_state(bus_endpt_t *endpt, int *p_state)
|
|
|
+static int recv_until_state(bus_endpt_t* endpt, int* p_state)
|
|
|
{
|
|
|
int rc;
|
|
|
- iobuffer_t *ans_pkt = NULL;
|
|
|
+ iobuffer_t* ans_pkt = NULL;
|
|
|
int type, epid, state;
|
|
|
|
|
|
rc = recv_until(endpt, BUS_TYPE_ENDPT_GET_STATE, &ans_pkt);
|
|
@@ -748,11 +776,11 @@ static int recv_until_state(bus_endpt_t *endpt, int *p_state)
|
|
|
iobuffer_destroy(ans_pkt);
|
|
|
|
|
|
*p_state = state;
|
|
|
-
|
|
|
+
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_send_pkt(bus_endpt_t *endpt, int epid, int type, iobuffer_t *pkt)
|
|
|
+TOOLKIT_API int bus_endpt_send_pkt(bus_endpt_t* endpt, int epid, int type, iobuffer_t* pkt)
|
|
|
{
|
|
|
int t;
|
|
|
int rc;
|
|
@@ -773,7 +801,7 @@ TOOLKIT_API int bus_endpt_send_pkt(bus_endpt_t *endpt, int epid, int type, iobuf
|
|
|
iobuffer_write_head(pkt, IOBUF_T_I4, &t, 0);
|
|
|
t = BUS_TYPE_PACKET; // type
|
|
|
iobuffer_write_head(pkt, IOBUF_T_I4, &t, 0);
|
|
|
-
|
|
|
+
|
|
|
rc = send_pkt_raw(endpt, pkt);
|
|
|
|
|
|
iobuffer_restore_read_state(pkt, read_state);
|
|
@@ -790,7 +818,7 @@ TOOLKIT_API int bus_endpt_send_pkt(bus_endpt_t *endpt, int epid, int type, iobuf
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_send_info(bus_endpt_t *endpt, int epid, int type, iobuffer_t *pkt)
|
|
|
+TOOLKIT_API int bus_endpt_send_info(bus_endpt_t* endpt, int epid, int type, iobuffer_t* pkt)
|
|
|
{
|
|
|
int t;
|
|
|
int rc;
|
|
@@ -819,7 +847,7 @@ TOOLKIT_API int bus_endpt_send_info(bus_endpt_t *endpt, int epid, int type, iobu
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_bcast_evt(bus_endpt_t *endpt, int type, iobuffer_t *pkt)
|
|
|
+TOOLKIT_API int bus_endpt_bcast_evt(bus_endpt_t* endpt, int type, iobuffer_t* pkt)
|
|
|
{
|
|
|
int t;
|
|
|
int rc;
|
|
@@ -830,7 +858,7 @@ TOOLKIT_API int bus_endpt_bcast_evt(bus_endpt_t *endpt, int type, iobuffer_t *pk
|
|
|
|
|
|
read_state = iobuffer_get_read_state(pkt);
|
|
|
write_state = iobuffer_get_write_state(pkt);
|
|
|
-
|
|
|
+
|
|
|
t = endpt->epid;
|
|
|
iobuffer_write_head(pkt, IOBUF_T_I4, &t, 0);
|
|
|
t = type;
|
|
@@ -843,13 +871,13 @@ TOOLKIT_API int bus_endpt_bcast_evt(bus_endpt_t *endpt, int type, iobuffer_t *pk
|
|
|
iobuffer_restore_read_state(pkt, read_state);
|
|
|
iobuffer_restore_write_state(pkt, write_state);
|
|
|
|
|
|
- return rc;
|
|
|
+ return rc;
|
|
|
}
|
|
|
|
|
|
-static int bus_endpt_recv_pkt(bus_endpt_t *endpt, int *p_epid, int *p_type, iobuffer_t **p_pkt)
|
|
|
+static int bus_endpt_recv_pkt(bus_endpt_t* endpt, int* p_epid, int* p_type, iobuffer_t** p_pkt)
|
|
|
{
|
|
|
if (iobuffer_queue_count(endpt->rx_buf_queue) > 0) {
|
|
|
- iobuffer_t *pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
+ iobuffer_t* pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
int read_state = iobuffer_get_read_state(pkt);
|
|
|
int pkt_type, usr_type, from_epid, to_epid;
|
|
|
iobuffer_read(pkt, IOBUF_T_I4, &pkt_type, 0);
|
|
@@ -864,21 +892,23 @@ static int bus_endpt_recv_pkt(bus_endpt_t *endpt, int *p_epid, int *p_type, iobu
|
|
|
iobuffer_queue_deque(endpt->rx_buf_queue);
|
|
|
if (p_pkt) {
|
|
|
*p_pkt = pkt;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
iobuffer_destroy(pkt);
|
|
|
}
|
|
|
return 0;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
iobuffer_restore_read_state(pkt, read_state);
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-static int bus_endpt_recv_evt(bus_endpt_t *endpt, int *p_epid, int *p_type, iobuffer_t **p_pkt)
|
|
|
+static int bus_endpt_recv_evt(bus_endpt_t* endpt, int* p_epid, int* p_type, iobuffer_t** p_pkt)
|
|
|
{
|
|
|
if (iobuffer_queue_count(endpt->rx_buf_queue) > 0) {
|
|
|
- iobuffer_t *pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
+ iobuffer_t* pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
int read_state = iobuffer_get_read_state(pkt);
|
|
|
int pkt_type, usr_type, from_epid;
|
|
|
iobuffer_read(pkt, IOBUF_T_I4, &pkt_type, 0);
|
|
@@ -892,21 +922,23 @@ static int bus_endpt_recv_evt(bus_endpt_t *endpt, int *p_epid, int *p_type, iobu
|
|
|
iobuffer_queue_deque(endpt->rx_buf_queue);
|
|
|
if (p_pkt) {
|
|
|
*p_pkt = pkt;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
iobuffer_destroy(pkt);
|
|
|
}
|
|
|
return 0;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
iobuffer_restore_read_state(pkt, read_state);
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-static int bus_endpt_recv_sys(bus_endpt_t *endpt, int *p_epid, int *p_state)
|
|
|
+static int bus_endpt_recv_sys(bus_endpt_t* endpt, int* p_epid, int* p_state)
|
|
|
{
|
|
|
if (iobuffer_queue_count(endpt->rx_buf_queue) > 0) {
|
|
|
- iobuffer_t *pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
+ iobuffer_t* pkt = iobuffer_queue_head(endpt->rx_buf_queue);
|
|
|
int read_state = iobuffer_get_read_state(pkt);
|
|
|
int pkt_type, epid, state;
|
|
|
iobuffer_read(pkt, IOBUF_T_I4, &pkt_type, 0);
|
|
@@ -920,14 +952,15 @@ static int bus_endpt_recv_sys(bus_endpt_t *endpt, int *p_epid, int *p_state)
|
|
|
iobuffer_queue_deque(endpt->rx_buf_queue);
|
|
|
iobuffer_destroy(pkt);
|
|
|
return 0;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
iobuffer_restore_read_state(pkt, read_state);
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
-static int bus_endpt_recv_msg(bus_endpt_t *endpt, msg_t **p_msg)
|
|
|
+static int bus_endpt_recv_msg(bus_endpt_t* endpt, msg_t** p_msg)
|
|
|
{
|
|
|
int rc = -1;
|
|
|
|
|
@@ -936,7 +969,7 @@ static int bus_endpt_recv_msg(bus_endpt_t *endpt, msg_t **p_msg)
|
|
|
|
|
|
spinlock_enter(&endpt->msg_lock, -1);
|
|
|
if (!list_empty(&endpt->msg_list)) {
|
|
|
- msg_t *e = list_first_entry(&endpt->msg_list, msg_t, entry);
|
|
|
+ msg_t* e = list_first_entry(&endpt->msg_list, msg_t, entry);
|
|
|
list_del(&e->entry);
|
|
|
rc = 0;
|
|
|
*p_msg = e;
|
|
@@ -946,9 +979,9 @@ static int bus_endpt_recv_msg(bus_endpt_t *endpt, msg_t **p_msg)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_get_state(bus_endpt_t *endpt, int epid, int *p_state)
|
|
|
+TOOLKIT_API int bus_endpt_get_state(bus_endpt_t* endpt, int epid, int* p_state)
|
|
|
{
|
|
|
- iobuffer_t *buf = NULL;
|
|
|
+ iobuffer_t* buf = NULL;
|
|
|
int v;
|
|
|
int rc = -1;
|
|
|
|
|
@@ -968,15 +1001,15 @@ TOOLKIT_API int bus_endpt_get_state(bus_endpt_t *endpt, int epid, int *p_state)
|
|
|
|
|
|
on_error:
|
|
|
|
|
|
- if(buf)
|
|
|
+ if (buf)
|
|
|
iobuffer_destroy(buf);
|
|
|
|
|
|
- return rc;
|
|
|
+ return rc;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_post_msg(bus_endpt_t *endpt, int msg, int nparam, int params[])
|
|
|
+TOOLKIT_API int bus_endpt_post_msg(bus_endpt_t* endpt, int msg, int nparam, int params[])
|
|
|
{
|
|
|
- msg_t *e;
|
|
|
+ msg_t* e;
|
|
|
|
|
|
assert(endpt);
|
|
|
|
|
@@ -984,9 +1017,10 @@ TOOLKIT_API int bus_endpt_post_msg(bus_endpt_t *endpt, int msg, int nparam, int
|
|
|
e->type = msg;
|
|
|
e->nparam = nparam;
|
|
|
if (nparam) {
|
|
|
- e->params = (int*)malloc(sizeof(int)*nparam);
|
|
|
- memcpy(e->params, params, sizeof(int)*nparam);
|
|
|
- } else {
|
|
|
+ e->params = (int*)malloc(sizeof(int) * nparam);
|
|
|
+ memcpy(e->params, params, sizeof(int) * nparam);
|
|
|
+ }
|
|
|
+ else {
|
|
|
e->params = NULL;
|
|
|
}
|
|
|
e->evt = NULL;
|
|
@@ -998,7 +1032,7 @@ TOOLKIT_API int bus_endpt_post_msg(bus_endpt_t *endpt, int msg, int nparam, int
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_send_msg(bus_endpt_t *endpt, int msg, int nparam, int params[])
|
|
|
+TOOLKIT_API int bus_endpt_send_msg(bus_endpt_t* endpt, int msg, int nparam, int params[])
|
|
|
{
|
|
|
msg_t e;
|
|
|
|
|
@@ -1007,9 +1041,10 @@ TOOLKIT_API int bus_endpt_send_msg(bus_endpt_t *endpt, int msg, int nparam, int
|
|
|
e.type = msg;
|
|
|
e.nparam = nparam;
|
|
|
if (nparam) {
|
|
|
- e.params = (int*)malloc(sizeof(int)*nparam);
|
|
|
- memcpy(e.params, params, sizeof(int)*nparam);
|
|
|
- } else {
|
|
|
+ e.params = (int*)malloc(sizeof(int) * nparam);
|
|
|
+ memcpy(e.params, params, sizeof(int) * nparam);
|
|
|
+ }
|
|
|
+ else {
|
|
|
e.params = NULL;
|
|
|
}
|
|
|
e.evt_result = 0;
|
|
@@ -1029,22 +1064,22 @@ TOOLKIT_API int bus_endpt_send_msg(bus_endpt_t *endpt, int msg, int nparam, int
|
|
|
return e.evt_result;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_get_epid(bus_endpt_t *endpt)
|
|
|
+TOOLKIT_API int bus_endpt_get_epid(bus_endpt_t* endpt)
|
|
|
{
|
|
|
return endpt->epid;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API const char *bus_endpt_get_url(bus_endpt_t *endpt)
|
|
|
+TOOLKIT_API const char* bus_endpt_get_url(bus_endpt_t* endpt)
|
|
|
{
|
|
|
return endpt->url;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_poll(bus_endpt_t *endpt, int timeout)
|
|
|
+TOOLKIT_API int bus_endpt_poll(bus_endpt_t* endpt, int timeout)
|
|
|
{
|
|
|
int result;
|
|
|
int rc;
|
|
|
int epid, type, state;
|
|
|
- iobuffer_t *pkt = NULL;
|
|
|
+ iobuffer_t* pkt = NULL;
|
|
|
|
|
|
rc = bus_endpt_poll_internal(endpt, &result, timeout);
|
|
|
if (rc > 0) {
|
|
@@ -1054,40 +1089,47 @@ TOOLKIT_API int bus_endpt_poll(bus_endpt_t *endpt, int timeout)
|
|
|
endpt->callback.on_pkt(endpt, epid, type, &pkt, endpt->callback.user_data);
|
|
|
if (pkt)
|
|
|
iobuffer_dec_ref(pkt);
|
|
|
- } else if (result == BUS_RESULT_INFO) {
|
|
|
+ }
|
|
|
+ else if (result == BUS_RESULT_INFO) {
|
|
|
bus_endpt_recv_pkt(endpt, &epid, &type, &pkt);
|
|
|
if (endpt->callback.on_inf)
|
|
|
endpt->callback.on_inf(endpt, epid, type, &pkt, endpt->callback.user_data);
|
|
|
if (pkt)
|
|
|
iobuffer_dec_ref(pkt);
|
|
|
- } else if (result == BUS_RESULT_EVENT) {
|
|
|
+ }
|
|
|
+ else if (result == BUS_RESULT_EVENT) {
|
|
|
bus_endpt_recv_evt(endpt, &epid, &type, &pkt);
|
|
|
if (endpt->callback.on_evt)
|
|
|
endpt->callback.on_evt(endpt, epid, type, &pkt, endpt->callback.user_data);
|
|
|
if (pkt)
|
|
|
iobuffer_dec_ref(pkt);
|
|
|
- } else if (result == BUS_RESULT_SYSTEM) {
|
|
|
+ }
|
|
|
+ else if (result == BUS_RESULT_SYSTEM) {
|
|
|
bus_endpt_recv_sys(endpt, &epid, &state);
|
|
|
if (endpt->callback.on_sys)
|
|
|
endpt->callback.on_sys(endpt, epid, state, endpt->callback.user_data);
|
|
|
- } else if (result == BUS_RESULT_MSG) {
|
|
|
- msg_t *msg = NULL;
|
|
|
+ }
|
|
|
+ else if (result == BUS_RESULT_MSG) {
|
|
|
+ msg_t* msg = NULL;
|
|
|
bus_endpt_recv_msg(endpt, &msg);
|
|
|
if (endpt->callback.on_msg) {
|
|
|
- endpt->callback.on_msg(endpt, msg->type, msg->nparam, msg->params, msg->evt ? &msg->evt_result : NULL, endpt->callback.user_data);
|
|
|
+ endpt->callback.on_msg(endpt, msg->type, msg->nparam, msg->params, msg->evt ? &msg->evt_result : NULL, endpt->callback.user_data);
|
|
|
if (msg->evt)
|
|
|
SetEvent(msg->evt);
|
|
|
- else
|
|
|
+ else
|
|
|
free_msg(msg);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
if (msg->evt) {
|
|
|
msg->evt_result = -1;
|
|
|
SetEvent(msg->evt);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
free_msg(msg);
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
assert(0);
|
|
|
rc = -1;
|
|
|
}
|
|
@@ -1096,13 +1138,13 @@ TOOLKIT_API int bus_endpt_poll(bus_endpt_t *endpt, int timeout)
|
|
|
return rc;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_set_quit_flag(bus_endpt_t *endpt)
|
|
|
+TOOLKIT_API int bus_endpt_set_quit_flag(bus_endpt_t* endpt)
|
|
|
{
|
|
|
endpt->quit_flag = 1;
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-TOOLKIT_API int bus_endpt_get_quit_flag(bus_endpt_t *endpt)
|
|
|
+TOOLKIT_API int bus_endpt_get_quit_flag(bus_endpt_t* endpt)
|
|
|
{
|
|
|
return endpt->quit_flag;
|
|
|
}
|