clean up socket stuff a little bit to compile better with msys2

This commit is contained in:
Kelvin Sherlock 2019-02-19 21:57:52 -05:00
parent 9f3c0feb39
commit 62dcf4f9d2
6 changed files with 26 additions and 36 deletions

View File

@ -6,6 +6,7 @@
*/ */
#include "defc.h" #include "defc.h"
#include "scc.h"
#include "scc_llap.h" #include "scc_llap.h"
#ifdef UNDER_CE #ifdef UNDER_CE
@ -25,7 +26,6 @@ extern int g_appletalk_turbo;
/* my scc port 0 == channel A = slot 1 = c039/c03b */ /* my scc port 0 == channel A = slot 1 = c039/c03b */
/* port 1 == channel B = slot 2 = c038/c03a */ /* port 1 == channel B = slot 2 = c038/c03a */
#include "scc.h"
#define SCC_R14_DPLL_SOURCE_BRG 0x100 #define SCC_R14_DPLL_SOURCE_BRG 0x100
#define SCC_R14_FM_MODE 0x200 #define SCC_R14_FM_MODE 0x200

View File

@ -5,14 +5,13 @@
See LICENSE.txt for license (GPL v2) See LICENSE.txt for license (GPL v2)
*/ */
#include <ctype.h>
#ifdef _WIN32 #ifdef _WIN32
# include <winsock2.h> # include <winsock2.h>
#else #else
# include <sys/socket.h> # include <sys/socket.h>
# include <netinet/in.h> # include <netinet/in.h>
# include <netdb.h> # include <netdb.h>
typedef int SOCKET;
#endif #endif
#if defined(HPUX) || defined(__linux__) || defined(SOLARIS) || defined(MAC) || defined(__MACH__) || defined(_WIN32) #if defined(HPUX) || defined(__linux__) || defined(SOLARIS) || defined(MAC) || defined(__MACH__) || defined(_WIN32)
@ -28,10 +27,6 @@
#define SCC_MODEM_MAX_CMD_STR 128 #define SCC_MODEM_MAX_CMD_STR 128
#ifndef SOCKET
# define SOCKET word32 /* for non-windows */
#endif
STRUCT(Scc) { STRUCT(Scc) {
int port; int port;
int state /* 0 == disconnected, 1 == real serial port, 2 == socket, 3 == LocalTalk */; int state /* 0 == disconnected, 1 == real serial port, 2 == socket, 3 == LocalTalk */;

View File

@ -8,8 +8,9 @@
/* This is an interface between the SCC emulation and the Virtual Imagewriter. */ /* This is an interface between the SCC emulation and the Virtual Imagewriter. */
#include "defc.h" #include "defc.h"
#include "scc.h"
#include "imagewriter.h" #include "imagewriter.h"
#include "scc.h"
extern Scc scc_stat[2]; extern Scc scc_stat[2];
extern word32 g_vbl_count; extern word32 g_vbl_count;

View File

@ -7,17 +7,16 @@
/* This file contains the Mac serial calls */ /* This file contains the Mac serial calls */
#ifdef MAC
#include "defc.h" #include "defc.h"
#include "scc.h" #include "scc.h"
#ifndef _WIN32 #include <termios.h>
# include <termios.h>
#endif
extern Scc scc_stat[2]; extern Scc scc_stat[2];
extern word32 g_c025_val; extern word32 g_c025_val;
#ifdef MAC
int scc_serial_mac_init(int port) { int scc_serial_mac_init(int port) {
char str_buf[1024]; char str_buf[1024];
Scc *scc_ptr; Scc *scc_ptr;

View File

@ -14,17 +14,16 @@
#ifndef UNDER_CE //OG #ifndef UNDER_CE //OG
#include <signal.h> #include <signal.h>
#endif #endif
#ifdef __CYGWIN__
#ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#define socklen_t int
#endif #endif
extern Scc scc_stat[2]; extern Scc scc_stat[2];
extern int g_serial_modem[]; extern int g_serial_modem[];
#if !(defined _WIN32)
extern int h_errno;
#else
#define socklen_t int
#endif
int g_wsastartup_called = 0; int g_wsastartup_called = 0;
typedef unsigned short USHORT; typedef unsigned short USHORT;
@ -108,19 +107,17 @@ void scc_socket_maybe_open_incoming(int port, double dcycs) {
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0);
printf("sockfd ret: %d\n", sockfd); printf("sockfd ret: %d\n", sockfd);
if(sockfd == -1) { if(sockfd == -1) {
printf("socket ret: %d, errno: %d\n", sockfd, errno); perror("socket");
scc_socket_close(port, 0, dcycs); scc_socket_close(port, 0, dcycs);
scc_ptr->socket_state = -1; scc_ptr->socket_state = -1;
return; return;
} }
/* printf("socket ret: %d\n", sockfd); */
on = 1; on = 1;
ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof(on)); (char *)&on, sizeof(on));
if(ret < 0) { if(ret < 0) {
printf("setsockopt REUSEADDR ret: %d, err:%d\n", perror("setsockopt REUSEADDR");
ret, errno);
scc_socket_close(port, 0, dcycs); scc_socket_close(port, 0, dcycs);
scc_ptr->socket_state = -1; scc_ptr->socket_state = -1;
return; return;
@ -138,7 +135,7 @@ void scc_socket_maybe_open_incoming(int port, double dcycs) {
break; break;
} }
/* else ret to bind was < 0 */ /* else ret to bind was < 0 */
printf("bind ret: %d, errno: %d\n", ret, errno); perror("bind");
inc++; inc++;
scc_socket_close_handle(sockfd); scc_socket_close_handle(sockfd);
printf("Trying next port: %d\n", 6501 + port + inc); printf("Trying next port: %d\n", 6501 + port + inc);
@ -180,7 +177,7 @@ void scc_socket_open_outgoing(int port, double dcycs) {
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0);
printf("sockfd ret: %d\n", sockfd); printf("sockfd ret: %d\n", sockfd);
if(sockfd == -1) { if(sockfd == -1) {
printf("socket ret: %d, errno: %d\n", sockfd, errno); perror("socket");
scc_socket_close(port, 1, dcycs); scc_socket_close(port, 1, dcycs);
return; return;
} }
@ -190,8 +187,7 @@ void scc_socket_open_outgoing(int port, double dcycs) {
ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
(char *)&on, sizeof(on)); (char *)&on, sizeof(on));
if(ret < 0) { if(ret < 0) {
printf("setsockopt REUSEADDR ret: %d, err:%d\n", perror("setsockopt REUSEADDR");
ret, errno);
scc_socket_close(port, 1, dcycs); scc_socket_close(port, 1, dcycs);
return; return;
} }
@ -218,9 +214,9 @@ void scc_socket_open_outgoing(int port, double dcycs) {
hostentptr = gethostbyname((const char*)&scc_ptr->modem_cmd_str[0]); // OG Added Cast hostentptr = gethostbyname((const char*)&scc_ptr->modem_cmd_str[0]); // OG Added Cast
if(hostentptr == 0) { if(hostentptr == 0) {
#if defined(_WIN32) #if defined(_WIN32)
fatal_printf("Lookup host %s failed\n", &scc_ptr->modem_cmd_str[0]); fatal_printf("gethostbyname %s failed\n", &scc_ptr->modem_cmd_str[0]);
#else #else
fatal_printf("Lookup host %s failed, herrno: %d\n", &scc_ptr->modem_cmd_str[0], h_errno); fatal_printf("gethostbyname %s failed: %s\n", &scc_ptr->modem_cmd_str[0], hstrerror(h_errno));
#endif #endif
scc_socket_close_handle(sockfd); scc_socket_close_handle(sockfd);
scc_socket_close(port, 1, dcycs); scc_socket_close(port, 1, dcycs);
@ -234,7 +230,7 @@ void scc_socket_open_outgoing(int port, double dcycs) {
ret = connect(sockfd, (struct sockaddr *)&sa_in, sizeof(sa_in)); ret = connect(sockfd, (struct sockaddr *)&sa_in, sizeof(sa_in));
if(ret < 0) { if(ret < 0) {
printf("connect ret: %d, errno: %d\n", ret, errno); perror("connect");
scc_socket_close_handle(sockfd); scc_socket_close_handle(sockfd);
scc_socket_close(port, 1, dcycs); scc_socket_close(port, 1, dcycs);
return; return;
@ -276,14 +272,14 @@ void scc_socket_make_nonblock(int port, double dcycs) {
#else #else
flags = fcntl(sockfd, F_GETFL, 0); flags = fcntl(sockfd, F_GETFL, 0);
if(flags == -1) { if(flags == -1) {
printf("fcntl GETFL ret: %d, errno: %d\n", flags, errno); perror("fcntl GETFL");
scc_socket_close(port, 1, dcycs); scc_socket_close(port, 1, dcycs);
scc_ptr->socket_state = -1; scc_ptr->socket_state = -1;
return; return;
} }
ret = fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); ret = fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
if(ret == -1) { if(ret == -1) {
printf("fcntl SETFL ret: %d, errno: %d\n", ret, errno); perror("fcntl SETFL");
scc_socket_close(port, 1, dcycs); scc_socket_close(port, 1, dcycs);
scc_ptr->socket_state = -1; scc_ptr->socket_state = -1;
return; return;
@ -374,12 +370,12 @@ void scc_accept_socket(int port, double dcycs) {
/* For Linux, we need to set O_NONBLOCK on the rdwrfd */ /* For Linux, we need to set O_NONBLOCK on the rdwrfd */
flags = fcntl(rdwrfd, F_GETFL, 0); flags = fcntl(rdwrfd, F_GETFL, 0);
if(flags == -1) { if(flags == -1) {
printf("fcntl GETFL ret: %d, errno: %d\n", flags,errno); perror("fcntl GETFL");
return; return;
} }
ret = fcntl(rdwrfd, F_SETFL, flags | O_NONBLOCK); ret = fcntl(rdwrfd, F_SETFL, flags | O_NONBLOCK);
if(ret == -1) { if(ret == -1) {
printf("fcntl SETFL ret: %d, errno: %d\n", ret, errno); perror("fcntl SETFL");
return; return;
} }
#endif #endif

View File

@ -7,13 +7,13 @@
/* This file contains the Win32 COM1/COM2 calls */ /* This file contains the Win32 COM1/COM2 calls */
#ifdef _WIN32
#include "defc.h" #include "defc.h"
#include "scc.h" #include "scc.h"
#ifdef __CYGWIN__
#include <Windows.h> #include <Windows.h>
#include <NspAPI.h> #include <NspAPI.h>
#endif
#ifdef UNDER_CE #ifdef UNDER_CE
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
@ -22,7 +22,6 @@
extern Scc scc_stat[2]; extern Scc scc_stat[2];
extern word32 g_c025_val; extern word32 g_c025_val;
#ifdef _WIN32
int scc_serial_win_init(int port) { int scc_serial_win_init(int port) {
COMMTIMEOUTS commtimeouts; COMMTIMEOUTS commtimeouts;
TCHAR str_buf[8]; TCHAR str_buf[8];