Implement sock_sendmsg_t and sock_recvmsg_t.

This commit is contained in:
Vincent Wei
2020-01-06 15:02:48 +08:00
parent 103470b92d
commit f8af8b7295
+73 -19
View File
@@ -11,35 +11,35 @@
//
//////////////////////////////////////////////////////////////////////////////
/*
* This file is part of MiniGUI, a mature cross-platform windowing
* This file is part of MiniGUI, a mature cross-platform windowing
* and Graphics User Interface (GUI) support system for embedded systems
* and smart IoT devices.
*
*
* Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd.
* Copyright (C) 1998~2002, WEI Yongming
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
* Or,
*
*
* As this program is a library, any link to this program must follow
* GNU General Public License version 3 (GPLv3). If you cannot accept
* GPLv3, you need to be licensed from FMSoft.
*
*
* If you have got a commercial license of this program, please use it
* under the terms and conditions of the commercial license.
*
*
* For more information about the commercial license, please refer to
* <http://www.minigui.com/blog/minigui-licensing-policy/>.
*/
@@ -70,13 +70,14 @@
#include "sharedres.h"
#include "sockio.h"
int sock_write_t (int fd, const void* buff, int count, unsigned int timeout)
ssize_t sock_write_t (int fd, const void* buff, size_t count, DWORD timeout)
{
const void* pts = buff;
int status = 0, n;
unsigned int start_tick = SHAREDRES_TIMER_COUNTER;
ssize_t status = 0, n;
DWORD start_tick = SHAREDRES_TIMER_COUNTER;
if (count < 0) return SOCKERR_OK;
if (count == 0)
return SOCKERR_OK;
while (status != count) {
n = write (fd, pts + status, count - status);
@@ -84,8 +85,7 @@ int sock_write_t (int fd, const void* buff, int count, unsigned int timeout)
if (errno == EPIPE)
return SOCKERR_CLOSED;
else if (errno == EINTR) {
if (timeout && (SHAREDRES_TIMER_COUNTER
> start_tick + timeout)) {
if (timeout && (SHAREDRES_TIMER_COUNTER > start_tick + timeout)) {
return SOCKERR_TIMEOUT;
}
continue;
@@ -99,11 +99,11 @@ int sock_write_t (int fd, const void* buff, int count, unsigned int timeout)
return status;
}
int sock_read_t (int fd, void* buff, int count, unsigned int timeout)
ssize_t sock_read_t (int fd, void* buff, size_t count, DWORD timeout)
{
void* pts = buff;
int status = 0, n;
unsigned int start_tick = SHAREDRES_TIMER_COUNTER;
ssize_t status = 0, n;
DWORD start_tick = SHAREDRES_TIMER_COUNTER;
if (count <= 0) return SOCKERR_OK;
while (status != count) {
@@ -127,4 +127,58 @@ int sock_read_t (int fd, void* buff, int count, unsigned int timeout)
return status;
}
#endif
ssize_t sock_sendmsg_t (int fd, const struct msghdr *msg, int flags, DWORD timeout)
{
ssize_t n;
DWORD start_tick = SHAREDRES_TIMER_COUNTER;
if (msg == NULL)
return SOCKERR_OK;
do {
n = sendmsg (fd, msg, flags);
if (n < 0) {
if (errno == EPIPE)
return SOCKERR_CLOSED;
else if (errno == EINTR) {
if (timeout && (SHAREDRES_TIMER_COUNTER > start_tick + timeout)) {
return SOCKERR_TIMEOUT;
}
}
else
return SOCKERR_IO;
}
} while (n < 0);
return n;
}
ssize_t sock_recvmsg_t (int fd, struct msghdr *msg, int flags, DWORD timeout)
{
ssize_t n;
DWORD start_tick = SHAREDRES_TIMER_COUNTER;
if (msg == NULL)
return SOCKERR_OK;
do {
n = recvmsg (fd, msg, flags);
if (n < 0) {
if (errno == EPIPE)
return SOCKERR_CLOSED;
else if (errno == EINTR) {
if (timeout && (SHAREDRES_TIMER_COUNTER > start_tick + timeout)) {
return SOCKERR_TIMEOUT;
}
}
else
return SOCKERR_IO;
}
} while (n < 0);
return n;
}
#endif