mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
@@ -30,7 +30,8 @@ extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
|
|||||||
static inline uint32_t board_millis(void) {
|
static inline uint32_t board_millis(void) {
|
||||||
struct timeval start;
|
struct timeval start;
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
return start.tv_sec * 1000 + start.tv_usec / 1000;
|
uint64_t ms = (uint64_t)start.tv_sec * 1000ULL + (uint64_t)start.tv_usec / 1000ULL;
|
||||||
|
return (uint32_t)ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _BOARD_H_
|
#endif // _BOARD_H_
|
||||||
|
|||||||
@@ -216,7 +216,11 @@ uint16_t driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_s
|
|||||||
uint16_t size = htons(buffer_size);
|
uint16_t size = htons(buffer_size);
|
||||||
socket_t sock = get_sock_itf(itf);
|
socket_t sock = get_sock_itf(itf);
|
||||||
// DEBUG_PAYLOAD(buffer,buffer_size);
|
// DEBUG_PAYLOAD(buffer,buffer_size);
|
||||||
|
#ifdef _WIN32
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
#else
|
||||||
|
ssize_t ret = 0;
|
||||||
|
#endif
|
||||||
do {
|
do {
|
||||||
ret = send(sock, (const char *)&size, sizeof(size), 0);
|
ret = send(sock, (const char *)&size, sizeof(size), 0);
|
||||||
if (ret == SOCKET_ERROR) {
|
if (ret == SOCKET_ERROR) {
|
||||||
@@ -295,7 +299,11 @@ uint16_t emul_read(uint8_t itf) {
|
|||||||
__pragma(warning(pop))
|
__pragma(warning(pop))
|
||||||
#endif
|
#endif
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
|
#ifdef _WIN32
|
||||||
int valread = 0;
|
int valread = 0;
|
||||||
|
#else
|
||||||
|
ssize_t valread = 0;
|
||||||
|
#endif
|
||||||
timeout.tv_sec = 0;
|
timeout.tv_sec = 0;
|
||||||
timeout.tv_usec = 0 * 1000;
|
timeout.tv_usec = 0 * 1000;
|
||||||
int n = select((int)(sock + 1), &input, NULL, NULL, &timeout);
|
int n = select((int)(sock + 1), &input, NULL, NULL, &timeout);
|
||||||
|
|||||||
@@ -306,10 +306,11 @@ void rest_close_conn(rest_conn_t *conn) {
|
|||||||
mbedtls_ssl_free(&conn->ssl);
|
mbedtls_ssl_free(&conn->ssl);
|
||||||
}
|
}
|
||||||
if (conn->sock >= 0) {
|
if (conn->sock >= 0) {
|
||||||
|
socket_t fd = (socket_t)conn->sock;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
shutdown((SOCKET)conn->sock, 1);
|
shutdown((SOCKET)fd, 1);
|
||||||
#endif
|
#endif
|
||||||
(void)close(conn->sock);
|
(void)close(fd);
|
||||||
}
|
}
|
||||||
clear_conn(conn);
|
clear_conn(conn);
|
||||||
#else
|
#else
|
||||||
@@ -445,7 +446,7 @@ static void send_response(rest_conn_t *conn, int status_code, const char *status
|
|||||||
}
|
}
|
||||||
#ifdef ENABLE_EMULATION
|
#ifdef ENABLE_EMULATION
|
||||||
while (sent_total < (size_t)header_len) {
|
while (sent_total < (size_t)header_len) {
|
||||||
int n = send((socket_t)conn->sock, headers_buf + sent_total, (int)((size_t)header_len - sent_total), 0);
|
ssize_t n = send((socket_t)conn->sock, headers_buf + sent_total, (int)((size_t)header_len - sent_total), 0);
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
rest_close_conn(conn);
|
rest_close_conn(conn);
|
||||||
return;
|
return;
|
||||||
@@ -454,7 +455,7 @@ static void send_response(rest_conn_t *conn, int status_code, const char *status
|
|||||||
}
|
}
|
||||||
sent_total = 0;
|
sent_total = 0;
|
||||||
while (sent_total < body_len) {
|
while (sent_total < body_len) {
|
||||||
int n = send((socket_t)conn->sock, body + sent_total, (int)(body_len - sent_total), 0);
|
ssize_t n = send((socket_t)conn->sock, body + sent_total, (int)(body_len - sent_total), 0);
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
rest_close_conn(conn);
|
rest_close_conn(conn);
|
||||||
return;
|
return;
|
||||||
@@ -1285,7 +1286,7 @@ static void *rest_emulation_thread(void *arg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int n = recv((socket_t)conn->sock, conn->request + conn->request_len, (int)(REST_MAX_REQUEST_SIZE - conn->request_len), 0);
|
ssize_t n = recv((socket_t)conn->sock, conn->request + conn->request_len, (int)(REST_MAX_REQUEST_SIZE - conn->request_len), 0);
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
rest_close_conn(conn);
|
rest_close_conn(conn);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -190,9 +190,9 @@ int emulation_rest_tls_port(void) {
|
|||||||
|
|
||||||
int tls_send_cb(void *ctx, const unsigned char *buf, size_t len) {
|
int tls_send_cb(void *ctx, const unsigned char *buf, size_t len) {
|
||||||
const socket_t fd = (socket_t)(*(const intptr_t *)ctx);
|
const socket_t fd = (socket_t)(*(const intptr_t *)ctx);
|
||||||
int r = send(fd, (const char *)buf, (int)len, 0);
|
ssize_t r = send(fd, (const char *)buf, (int)len, 0);
|
||||||
if (r >= 0) {
|
if (r >= 0) {
|
||||||
return r;
|
return (int)r;
|
||||||
}
|
}
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
{
|
{
|
||||||
@@ -211,9 +211,9 @@ int tls_send_cb(void *ctx, const unsigned char *buf, size_t len) {
|
|||||||
|
|
||||||
int tls_recv_cb(void *ctx, unsigned char *buf, size_t len) {
|
int tls_recv_cb(void *ctx, unsigned char *buf, size_t len) {
|
||||||
const socket_t fd = (socket_t)(*(const intptr_t *)ctx);
|
const socket_t fd = (socket_t)(*(const intptr_t *)ctx);
|
||||||
int r = recv(fd, (char *)buf, (int)len, 0);
|
ssize_t r = recv(fd, (char *)buf, (int)len, 0);
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
return r;
|
return (int)r;
|
||||||
}
|
}
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
return MBEDTLS_ERR_SSL_CONN_EOF;
|
return MBEDTLS_ERR_SSL_CONN_EOF;
|
||||||
|
|||||||
Reference in New Issue
Block a user