|
|
@@ -11,6 +11,9 @@
|
|
|
#include <winpr/pipe.h>
|
|
|
#include <winpr/synch.h>
|
|
|
#include <winpr/string.h>
|
|
|
+#include <winpr/wlog.h>
|
|
|
+
|
|
|
+#define TAG TOOLKIT_TAG("bus")
|
|
|
|
|
|
#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
|
|
|
@@ -392,9 +395,9 @@ static int start_read_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
|
|
|
|
|
|
static int read_left_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
|
|
|
{
|
|
|
- BOOL ret;
|
|
|
+ BOOL ret = 0;
|
|
|
int rc;
|
|
|
- DWORD dwBytesTransferred;
|
|
|
+ DWORD dwBytesTransferred = 0;
|
|
|
iobuffer_t* pkt = NULL;
|
|
|
|
|
|
if (endpt->type == TYPE_PIPE) {
|
|
|
@@ -404,19 +407,25 @@ static int read_left_pkt(bus_endpt_t* endpt, iobuffer_t** p_pkt)
|
|
|
DWORD dwFlags = 0;
|
|
|
ret = WSAGetOverlappedResult(endpt->sock_handle, &endpt->rx_overlapped, &dwBytesTransferred, TRUE, &dwFlags);
|
|
|
}
|
|
|
+ else {
|
|
|
+ assert(0);
|
|
|
+ }
|
|
|
|
|
|
if (!ret || dwBytesTransferred == 0) {
|
|
|
- DWORD dwError = GetLastError();
|
|
|
+ WLog_ERR(TAG, "(WSA)GetOverlappedResult failed: %d", GetLastError());
|
|
|
return -1;
|
|
|
}
|
|
|
if (dwBytesTransferred < 4) {
|
|
|
rc = recv_buf(endpt, (char*)&endpt->rx_pending_pkt_len + dwBytesTransferred, 4 - dwBytesTransferred);
|
|
|
- if (rc < 0)
|
|
|
+ if (rc < 0) {
|
|
|
+ WLog_ERR(TAG, "recv buf failed.");
|
|
|
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) {
|
|
|
+ WLog_ERR(TAG, "recv buf failed and destroy buffer.");
|
|
|
iobuffer_destroy(pkt);
|
|
|
return rc;
|
|
|
}
|
|
|
@@ -661,20 +670,23 @@ static int bus_endpt_poll_internal(bus_endpt_t* endpt, int* result, int timeout)
|
|
|
}
|
|
|
else if (ret == WAIT_OBJECT_0 + 1) {
|
|
|
rc = read_left_pkt(endpt, &pkt);
|
|
|
- if (rc < 0)
|
|
|
+ if (rc < 0) {
|
|
|
+ WLog_ERR(TAG, "read_left_pkt failed: %d", rc);
|
|
|
return rc;
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
if (pkt) {
|
|
|
rc = append_rx_pkt(endpt, pkt);
|
|
|
if (rc < 0) {
|
|
|
iobuffer_destroy(pkt);
|
|
|
+ WLog_ERR(TAG, "append_rx_pkt failed: %d", rc);
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- OutputDebugStringA("pkt has readed\n");
|
|
|
+ WLog_ERR(TAG, "pkt has readed");
|
|
|
}
|
|
|
|
|
|
if (pkt) {
|
|
|
@@ -684,11 +696,12 @@ static int bus_endpt_poll_internal(bus_endpt_t* endpt, int* result, int timeout)
|
|
|
iobuffer_restore_read_state(pkt, read_state);
|
|
|
*result = to_result(type);
|
|
|
if (*result == BUS_RESULT_UNKNOWN) {
|
|
|
- OutputDebugStringA("bug: unknown pkt type!\n");
|
|
|
+ WLog_ERR(TAG, "bug: unknown pkt type!");
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
+ WLog_ERR(TAG, "not pkt");
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
@@ -1014,11 +1027,15 @@ TOOLKIT_API int bus_endpt_post_msg(bus_endpt_t* endpt, int msg, int nparam, int
|
|
|
assert(endpt);
|
|
|
|
|
|
e = MALLOC_T(msg_t);
|
|
|
+ if (e == NULL) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
e->type = msg;
|
|
|
e->nparam = nparam;
|
|
|
if (nparam) {
|
|
|
e->params = (int*)malloc(sizeof(int) * nparam);
|
|
|
- memcpy(e->params, params, sizeof(int) * nparam);
|
|
|
+ if(e->params != NULL)
|
|
|
+ memcpy(e->params, params, sizeof(int) * nparam);
|
|
|
}
|
|
|
else {
|
|
|
e->params = NULL;
|
|
|
@@ -1080,7 +1097,6 @@ TOOLKIT_API int bus_endpt_poll(bus_endpt_t* endpt, int timeout)
|
|
|
int rc;
|
|
|
int epid, type, state;
|
|
|
iobuffer_t* pkt = NULL;
|
|
|
-
|
|
|
rc = bus_endpt_poll_internal(endpt, &result, timeout);
|
|
|
if (rc > 0) {
|
|
|
if (result == BUS_RESULT_DATA) {
|
|
|
@@ -1134,6 +1150,9 @@ TOOLKIT_API int bus_endpt_poll(bus_endpt_t* endpt, int timeout)
|
|
|
rc = -1;
|
|
|
}
|
|
|
}
|
|
|
+ else if (rc < 0) {
|
|
|
+ WLog_DBG(TAG, "bus_endpt_poll_internal failed, rc = %d", rc);
|
|
|
+ }
|
|
|
|
|
|
return rc;
|
|
|
}
|