Skip to content

Commit b9df7d3

Browse files
committed
network digital outputs: check config option when game starts
Avoid the need to restart when enabling or disabling this option Send game name to newly connected sockets ignore SIGPIPE (telnet) Log network errors
1 parent bf1d4a5 commit b9df7d3

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

Diff for: core/hw/naomi/naomi.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ static void Naomi_DmaEnable(u32 addr, u32 data)
201201

202202
void naomi_reg_Init()
203203
{
204-
networkOutput.init();
205-
206204
static const u8 romSerialData[0x84] = {
207205
0x19, 0x00, 0xaa, 0x55,
208206
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

Diff for: core/linux/common.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ void os_InstallFaultHandler()
8787
#ifndef __SWITCH__
8888
struct sigaction act;
8989
memset(&act, 0, sizeof(act));
90+
act.sa_handler = SIG_IGN;
91+
sigaction(SIGPIPE, &act, nullptr);
92+
9093
act.sa_sigaction = fault_handler;
9194
sigemptyset(&act.sa_mask);
9295
act.sa_flags = SA_SIGINFO;

Diff for: core/network/net_platform.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ typedef int sock_t;
5555
#define L_EINPROGRESS EINPROGRESS
5656
#define get_last_error() (errno)
5757
#define INVALID_SOCKET (-1)
58-
#define perror(s) do { INFO_LOG(NETWORK, "%s: %s", (s) != NULL ? (s) : "", strerror(get_last_error())); } while (false)
58+
#define perror(s) do { ERROR_LOG(NETWORK, "%s: %s", (s) != NULL ? (s) : "", strerror(get_last_error())); } while (false)
5959
#else
6060
typedef SOCKET sock_t;
6161
#define VALID(s) ((s) != INVALID_SOCKET)
6262
#define L_EWOULDBLOCK WSAEWOULDBLOCK
6363
#define L_EAGAIN WSAEWOULDBLOCK
6464
#define L_EINPROGRESS WSAEINPROGRESS
6565
#define get_last_error() (WSAGetLastError())
66-
#define perror(s) do { INFO_LOG(NETWORK, "%s: Winsock error: %d", (s) != NULL ? (s) : "", WSAGetLastError()); } while (false)
66+
#define perror(s) do { ERROR_LOG(NETWORK, "%s: Winsock error: %d", (s) != NULL ? (s) : "", WSAGetLastError()); } while (false)
6767
#ifndef SHUT_WR
6868
#define SHUT_WR SD_SEND
6969
#endif

Diff for: core/network/output.h

+25-9
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@
2727

2828
class NetworkOutput
2929
{
30-
public:
3130
void init()
3231
{
33-
if (!config::NetworkOutput || settings.naomi.slave || settings.naomi.drivingSimSlave == 1)
32+
if (!config::NetworkOutput || settings.naomi.slave || settings.naomi.drivingSimSlave == 1) {
33+
term();
34+
return;
35+
}
36+
if (server != INVALID_SOCKET)
37+
// already done
3438
return;
3539
server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
3640

@@ -44,41 +48,41 @@ class NetworkOutput
4448
saddr.sin_port = htons(8000 + settings.naomi.drivingSimSlave);
4549
if (::bind(server, (sockaddr *)&saddr, saddr_len) < 0)
4650
{
47-
perror("bind");
51+
perror("Network output: bind failed");
4852
term();
4953
return;
5054
}
5155
if (listen(server, 5) < 0)
5256
{
53-
perror("listen");
57+
perror("Network output: listen failed");
5458
term();
5559
return;
5660
}
5761
set_non_blocking(server);
5862
EventManager::listen(Event::VBlank, vblankCallback, this);
5963
}
6064

65+
public:
6166
void term()
6267
{
6368
EventManager::unlisten(Event::VBlank, vblankCallback, this);
6469
for (sock_t sock : clients)
6570
closesocket(sock);
6671
clients.clear();
67-
if (server != INVALID_SOCKET)
68-
{
72+
if (server != INVALID_SOCKET) {
6973
closesocket(server);
7074
server = INVALID_SOCKET;
7175
}
7276
}
7377

74-
void reset()
75-
{
78+
void reset() {
79+
init();
7680
gameNameSent = false;
7781
}
7882

7983
void output(const char *name, u32 value)
8084
{
81-
if (!config::NetworkOutput || clients.empty())
85+
if (clients.empty())
8286
return;
8387
if (!gameNameSent)
8488
{
@@ -104,6 +108,18 @@ class NetworkOutput
104108
if (sockfd != INVALID_SOCKET)
105109
{
106110
set_non_blocking(sockfd);
111+
if (gameNameSent)
112+
{
113+
std::string msg = "game = " + settings.content.gameId + "\n";
114+
if (::send(sockfd, msg.c_str(), msg.length(), 0) < 0)
115+
{
116+
int error = get_last_error();
117+
if (error != L_EWOULDBLOCK && error != L_EAGAIN) {
118+
closesocket(sockfd);
119+
return;
120+
}
121+
}
122+
}
107123
clients.push_back(sockfd);
108124
}
109125
}

0 commit comments

Comments
 (0)