mirror of
https://github.com/86Box/86Box.git
synced 2025-01-22 09:11:50 -05:00
clang-format modem and serial passthrough related files
This commit is contained in:
parent
9a8bc1ab08
commit
0a1e92e239
7 changed files with 814 additions and 751 deletions
|
@ -370,12 +370,12 @@ static const device_config_t serial_passthrough_config[] = {
|
|||
// clang-format on
|
||||
|
||||
const device_t serial_passthrough_device = {
|
||||
.name = "Serial Passthrough Device",
|
||||
.flags = 0,
|
||||
.local = 0,
|
||||
.init = serial_passthrough_dev_init,
|
||||
.close = serial_passthrough_dev_close,
|
||||
.reset = NULL,
|
||||
.name = "Serial Passthrough Device",
|
||||
.flags = 0,
|
||||
.local = 0,
|
||||
.init = serial_passthrough_dev_init,
|
||||
.close = serial_passthrough_dev_close,
|
||||
.reset = NULL,
|
||||
{ .poll = NULL },
|
||||
.speed_changed = serial_passthrough_speed_changed,
|
||||
.force_redraw = NULL,
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
#ifndef _WIN32
|
||||
#define SOCKET int
|
||||
# define SOCKET int
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
# include <winsock2.h>
|
||||
# include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
enum net_socket_types
|
||||
{
|
||||
enum net_socket_types {
|
||||
/* Only TCP is supported for now. */
|
||||
NET_SOCKET_TCP
|
||||
};
|
||||
|
||||
SOCKET plat_netsocket_create(int type);
|
||||
SOCKET plat_netsocket_create_server(int type, unsigned short port);
|
||||
void plat_netsocket_close(SOCKET socket);
|
||||
void plat_netsocket_close(SOCKET socket);
|
||||
|
||||
SOCKET plat_netsocket_accept(SOCKET socket);
|
||||
int plat_netsocket_connected(SOCKET socket); /* Returns -1 on trouble. */
|
||||
int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short port);
|
||||
int plat_netsocket_connected(SOCKET socket); /* Returns -1 on trouble. */
|
||||
int plat_netsocket_connect(SOCKET socket, const char *hostname, unsigned short port);
|
||||
|
||||
/* Returns 0 in case of inability to send. -1 in case of errors. */
|
||||
int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int size, int *wouldblock);
|
||||
int plat_netsocket_receive(SOCKET socket, unsigned char* data, unsigned int size, int *wouldblock);
|
||||
int plat_netsocket_send(SOCKET socket, const unsigned char *data, unsigned int size, int *wouldblock);
|
||||
int plat_netsocket_receive(SOCKET socket, unsigned char *data, unsigned int size, int *wouldblock);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -19,50 +19,52 @@
|
|||
#include <ws2tcpip.h>
|
||||
#include <winerror.h>
|
||||
|
||||
SOCKET plat_netsocket_create(int type)
|
||||
SOCKET
|
||||
plat_netsocket_create(int type)
|
||||
{
|
||||
SOCKET socket = -1;
|
||||
u_long yes = 1;
|
||||
u_long yes = 1;
|
||||
|
||||
if (type != NET_SOCKET_TCP)
|
||||
return -1;
|
||||
|
||||
|
||||
socket = WSASocketA(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
|
||||
if (socket == INVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
ioctlsocket(socket, FIONBIO, &yes);
|
||||
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
||||
SOCKET
|
||||
plat_netsocket_create_server(int type, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in sock_addr;
|
||||
SOCKET socket = -1;
|
||||
u_long yes = 1;
|
||||
SOCKET socket = -1;
|
||||
u_long yes = 1;
|
||||
|
||||
if (type != NET_SOCKET_TCP)
|
||||
return -1;
|
||||
|
||||
|
||||
socket = WSASocketA(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
|
||||
if (socket == INVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
memset(&sock_addr, 0, sizeof(struct sockaddr_in));
|
||||
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
sock_addr.sin_port = htons(port);
|
||||
|
||||
if (bind(socket, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
|
||||
memset(&sock_addr, 0, sizeof(struct sockaddr_in));
|
||||
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
sock_addr.sin_port = htons(port);
|
||||
|
||||
if (bind(socket, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
|
||||
plat_netsocket_close(socket);
|
||||
return (SOCKET)-1;
|
||||
return (SOCKET) -1;
|
||||
}
|
||||
|
||||
if (listen(socket, 5) == SOCKET_ERROR) {
|
||||
plat_netsocket_close(socket);
|
||||
return (SOCKET)-1;
|
||||
return (SOCKET) -1;
|
||||
}
|
||||
|
||||
ioctlsocket(socket, FIONBIO, &yes);
|
||||
|
@ -70,28 +72,31 @@ SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
|||
return socket;
|
||||
}
|
||||
|
||||
void plat_netsocket_close(SOCKET socket)
|
||||
void
|
||||
plat_netsocket_close(SOCKET socket)
|
||||
{
|
||||
closesocket((SOCKET)socket);
|
||||
closesocket((SOCKET) socket);
|
||||
}
|
||||
|
||||
SOCKET plat_netsocket_accept(SOCKET socket)
|
||||
SOCKET
|
||||
plat_netsocket_accept(SOCKET socket)
|
||||
{
|
||||
SOCKET clientsocket = accept(socket, NULL, NULL);
|
||||
|
||||
if (clientsocket == INVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
|
||||
return clientsocket;
|
||||
}
|
||||
|
||||
int plat_netsocket_connected(SOCKET socket)
|
||||
int
|
||||
plat_netsocket_connected(SOCKET socket)
|
||||
{
|
||||
struct sockaddr addr;
|
||||
socklen_t len = sizeof(struct sockaddr);
|
||||
fd_set wrfds, exfds;
|
||||
struct timeval tv;
|
||||
int res = SOCKET_ERROR;
|
||||
int res = SOCKET_ERROR;
|
||||
int status = 0;
|
||||
int optlen = 4;
|
||||
|
||||
|
@ -107,21 +112,21 @@ int plat_netsocket_connected(SOCKET socket)
|
|||
|
||||
if (res == SOCKET_ERROR)
|
||||
return -1;
|
||||
|
||||
|
||||
if (res >= 1 && FD_ISSET(socket, &exfds)) {
|
||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char*)&status, &optlen);
|
||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char *) &status, &optlen);
|
||||
pclog("Socket error %d\n", status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (res == 0 || !(res >= 1 && FD_ISSET(socket, &wrfds)))
|
||||
return 0;
|
||||
|
||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char*)&status, &optlen);
|
||||
|
||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char *) &status, &optlen);
|
||||
|
||||
if (res == SOCKET_ERROR)
|
||||
return -1;
|
||||
|
||||
|
||||
if (status != 0)
|
||||
return -1;
|
||||
|
||||
|
@ -131,14 +136,15 @@ int plat_netsocket_connected(SOCKET socket)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short port)
|
||||
int
|
||||
plat_netsocket_connect(SOCKET socket, const char *hostname, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in sock_addr;
|
||||
int res = -1;
|
||||
int res = -1;
|
||||
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = inet_addr(hostname);
|
||||
sock_addr.sin_port = htons(port);
|
||||
sock_addr.sin_port = htons(port);
|
||||
|
||||
if (sock_addr.sin_addr.s_addr == INADDR_ANY || sock_addr.sin_addr.s_addr == INADDR_NONE) {
|
||||
struct hostent *hp;
|
||||
|
@ -151,22 +157,23 @@ int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short p
|
|||
return -1;
|
||||
}
|
||||
|
||||
res = connect(socket, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in));
|
||||
res = connect(socket, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in));
|
||||
|
||||
if (res == SOCKET_ERROR) {
|
||||
int error = WSAGetLastError();
|
||||
|
||||
if (error == WSAEISCONN || error == WSAEWOULDBLOCK)
|
||||
return 0;
|
||||
|
||||
|
||||
res = -1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int size, int *wouldblock)
|
||||
int
|
||||
plat_netsocket_send(SOCKET socket, const unsigned char *data, unsigned int size, int *wouldblock)
|
||||
{
|
||||
int res = send(socket, (const char*)data, size, 0);
|
||||
int res = send(socket, (const char *) data, size, 0);
|
||||
|
||||
if (res == SOCKET_ERROR) {
|
||||
int error = WSAGetLastError();
|
||||
|
@ -179,9 +186,10 @@ int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int s
|
|||
return res;
|
||||
}
|
||||
|
||||
int plat_netsocket_receive(SOCKET socket, unsigned char* data, unsigned int size, int *wouldblock)
|
||||
int
|
||||
plat_netsocket_receive(SOCKET socket, unsigned char *data, unsigned int size, int *wouldblock)
|
||||
{
|
||||
int res = recv(socket, (char*)data, size, 0);
|
||||
int res = recv(socket, (char *) data, size, 0);
|
||||
|
||||
if (res == SOCKET_ERROR) {
|
||||
int error = WSAGetLastError();
|
||||
|
|
|
@ -173,7 +173,7 @@ open_pseudo_terminal(serial_passthrough_t *dev)
|
|||
char ascii_pipe_name[1024] = { 0 };
|
||||
strncpy(ascii_pipe_name, dev->named_pipe, sizeof(ascii_pipe_name));
|
||||
ascii_pipe_name[1023] = '\0';
|
||||
dev->master_fd = (intptr_t) CreateNamedPipeA(ascii_pipe_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 65536, 65536, NMPWAIT_USE_DEFAULT_WAIT, NULL);
|
||||
dev->master_fd = (intptr_t) CreateNamedPipeA(ascii_pipe_name, PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, 1, 65536, 65536, NMPWAIT_USE_DEFAULT_WAIT, NULL);
|
||||
if (dev->master_fd == (intptr_t) INVALID_HANDLE_VALUE) {
|
||||
wchar_t errorMsg[1024] = { 0 };
|
||||
wchar_t finalMsg[1024] = { 0 };
|
||||
|
|
|
@ -19,91 +19,92 @@
|
|||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <unistd.h>
|
||||
|
||||
SOCKET plat_netsocket_create(int type)
|
||||
SOCKET
|
||||
plat_netsocket_create(int type)
|
||||
{
|
||||
SOCKET fd = -1;
|
||||
int yes = 1;
|
||||
SOCKET fd = -1;
|
||||
int yes = 1;
|
||||
|
||||
if (type != NET_SOCKET_TCP)
|
||||
return -1;
|
||||
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&yes, sizeof(yes));
|
||||
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof(yes));
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
||||
SOCKET
|
||||
plat_netsocket_create_server(int type, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in sock_addr;
|
||||
SOCKET fd = -1;
|
||||
int yes = 1;
|
||||
SOCKET fd = -1;
|
||||
int yes = 1;
|
||||
|
||||
if (type != NET_SOCKET_TCP)
|
||||
return -1;
|
||||
|
||||
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
memset(&sock_addr, 0, sizeof(struct sockaddr_in));
|
||||
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
sock_addr.sin_port = htons(port);
|
||||
|
||||
if (bind(fd, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in)) == -1) {
|
||||
memset(&sock_addr, 0, sizeof(struct sockaddr_in));
|
||||
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
sock_addr.sin_port = htons(port);
|
||||
|
||||
if (bind(fd, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in)) == -1) {
|
||||
plat_netsocket_close(fd);
|
||||
return (SOCKET)-1;
|
||||
return (SOCKET) -1;
|
||||
}
|
||||
|
||||
if (listen(fd, 5) == -1) {
|
||||
plat_netsocket_close(fd);
|
||||
return (SOCKET)-1;
|
||||
return (SOCKET) -1;
|
||||
}
|
||||
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&yes, sizeof(yes));
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof(yes));
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
void plat_netsocket_close(SOCKET socket)
|
||||
void
|
||||
plat_netsocket_close(SOCKET socket)
|
||||
{
|
||||
close((SOCKET)socket);
|
||||
close((SOCKET) socket);
|
||||
}
|
||||
|
||||
SOCKET plat_netsocket_accept(SOCKET socket)
|
||||
SOCKET
|
||||
plat_netsocket_accept(SOCKET socket)
|
||||
{
|
||||
SOCKET clientsocket = accept(socket, NULL, NULL);
|
||||
|
||||
if (clientsocket == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
return clientsocket;
|
||||
}
|
||||
|
||||
int plat_netsocket_connected(SOCKET socket)
|
||||
int
|
||||
plat_netsocket_connected(SOCKET socket)
|
||||
{
|
||||
struct sockaddr addr;
|
||||
socklen_t len = sizeof(struct sockaddr);
|
||||
fd_set wrfds;
|
||||
struct timeval tv;
|
||||
int res = -1;
|
||||
int res = -1;
|
||||
int status = 0;
|
||||
socklen_t optlen = 4;
|
||||
|
||||
|
@ -117,15 +118,15 @@ int plat_netsocket_connected(SOCKET socket)
|
|||
|
||||
if (res == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
if (res == 0 || !(res >= 1 && FD_ISSET(socket, &wrfds)))
|
||||
return 0;
|
||||
|
||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char*)&status, &optlen);
|
||||
|
||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char *) &status, &optlen);
|
||||
|
||||
if (res == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
if (status != 0)
|
||||
return -1;
|
||||
|
||||
|
@ -135,16 +136,17 @@ int plat_netsocket_connected(SOCKET socket)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short port)
|
||||
int
|
||||
plat_netsocket_connect(SOCKET socket, const char *hostname, unsigned short port)
|
||||
{
|
||||
struct sockaddr_in sock_addr;
|
||||
int res = -1;
|
||||
int res = -1;
|
||||
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_addr.s_addr = inet_addr(hostname);
|
||||
sock_addr.sin_port = htons(port);
|
||||
sock_addr.sin_port = htons(port);
|
||||
|
||||
if (sock_addr.sin_addr.s_addr == ((in_addr_t)-1) || sock_addr.sin_addr.s_addr == 0) {
|
||||
if (sock_addr.sin_addr.s_addr == ((in_addr_t) -1) || sock_addr.sin_addr.s_addr == 0) {
|
||||
struct hostent *hp;
|
||||
|
||||
hp = gethostbyname(hostname);
|
||||
|
@ -155,22 +157,23 @@ int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short p
|
|||
return -1;
|
||||
}
|
||||
|
||||
res = connect(socket, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in));
|
||||
res = connect(socket, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in));
|
||||
|
||||
if (res == -1) {
|
||||
int error = errno;
|
||||
|
||||
if (error == EISCONN || error == EWOULDBLOCK || error == EAGAIN || error == EINPROGRESS)
|
||||
return 0;
|
||||
|
||||
|
||||
res = -1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int size, int *wouldblock)
|
||||
int
|
||||
plat_netsocket_send(SOCKET socket, const unsigned char *data, unsigned int size, int *wouldblock)
|
||||
{
|
||||
int res = send(socket, (const char*)data, size, 0);
|
||||
int res = send(socket, (const char *) data, size, 0);
|
||||
|
||||
if (res == -1) {
|
||||
int error = errno;
|
||||
|
@ -183,9 +186,10 @@ int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int s
|
|||
return res;
|
||||
}
|
||||
|
||||
int plat_netsocket_receive(SOCKET socket, unsigned char* data, unsigned int size, int *wouldblock)
|
||||
int
|
||||
plat_netsocket_receive(SOCKET socket, unsigned char *data, unsigned int size, int *wouldblock)
|
||||
{
|
||||
int res = recv(socket, (char*)data, size, 0);
|
||||
int res = recv(socket, (char *) data, size, 0);
|
||||
|
||||
if (res == -1) {
|
||||
int error = errno;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
# define _BSD_SOURCE 1
|
||||
#endif
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
|
||||
# define __BSD_VISIBLE 1
|
||||
# define __BSD_VISIBLE 1
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
|
|
Loading…
Reference in a new issue