Skip to content

Commit

Permalink
cleanup for socket handling (nw)
Browse files Browse the repository at this point in the history
  • Loading branch information
SailorSat committed Oct 24, 2024
1 parent 0d52d1f commit 3ad5eeb
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 90 deletions.
34 changes: 28 additions & 6 deletions src/devices/machine/k056230.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,32 @@ void k056230_device::comm_tick()
{
if (m_linkenable == 0x01)
{
std::error_condition filerr;

// check rx socket
if (!m_line_rx)
{
osd_printf_verbose("k056230: listen on %s\n", m_localhost);
uint64_t filesize; // unused
osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
filerr = osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
if (filerr.value() != 0)
{
osd_printf_verbose("k056230: rx connection failed\n");
m_line_rx.reset();
}
}

// check tx socket
if ((!m_line_tx) && (m_txmode == 0x01))
{
osd_printf_verbose("k056230: connect to %s\n", m_remotehost);
uint64_t filesize; // unused
osd_file::open(m_remotehost, 0, m_line_tx, filesize);
filerr = osd_file::open(m_remotehost, 0, m_line_tx, filesize);
if (filerr.value() != 0)
{
osd_printf_verbose("k056230: tx connection failed\n");
m_line_tx.reset();
}
}

// if both sockets are there check ring
Expand Down Expand Up @@ -312,9 +324,17 @@ int k056230_device::read_frame(int dataSize)
togo -= recv;
offset += recv;
}
else if (filerr && filerr.value() != 0)
switch (filerr.value())
{
togo = 0;
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
togo = 0;
break;
}
}
}
Expand All @@ -323,8 +343,10 @@ int k056230_device::read_frame(int dataSize)
{
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
osd_printf_verbose("k056230: rx connection lost %08x %s\n", filerr.value(), filerr.message());
m_line_rx.reset();
Expand All @@ -342,7 +364,7 @@ void k056230_device::send_frame(int dataSize)
std::uint32_t written;

filerr = m_line_tx->write(&m_buffer0, 0, dataSize, written);
if (filerr && filerr.value() != 0)
if (filerr.value() != 0)
{
osd_printf_verbose("k056230: tx connection lost %08x %s\n", filerr.value(), filerr.message());
m_line_tx.reset();
Expand Down
62 changes: 42 additions & 20 deletions src/mame/sega/m1comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ void m1comm_device::comm_tick()
{
if (m_linkenable == 0x01)
{
std::error_condition filerr;

int frameStart = 0x0010;
int frameOffset = 0x0000;
int frameSize = 0x01c4;
Expand Down Expand Up @@ -342,15 +344,25 @@ void m1comm_device::comm_tick()
{
osd_printf_verbose("M1COMM: listen on %s\n", m_localhost);
uint64_t filesize; // unused
osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
filerr = osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
if (filerr.value() != 0)
{
osd_printf_verbose("M1COMM: rx connection failed\n");
m_line_rx.reset();
}
}

// check tx socket
if (!m_line_tx)
{
osd_printf_verbose("M1COMM: connect to %s\n", m_remotehost);
uint64_t filesize; // unused
osd_file::open(m_remotehost, 0, m_line_tx, filesize);
filerr = osd_file::open(m_remotehost, 0, m_line_tx, filesize);
if (filerr.value() != 0)
{
osd_printf_verbose("M1COMM: tx connection failed\n");
m_line_tx.reset();
}
}

// if both sockets are there check ring
Expand Down Expand Up @@ -581,26 +593,39 @@ int m1comm_device::read_frame(int dataSize)
togo -= recv;
offset += recv;
}
else if (!filerr && recv == 0)
switch (filerr.value())
{
togo = 0;
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
togo = 0;
break;
}
}
}
}
else if (!filerr && recv == 0)
switch (filerr.value())
{
if (m_linkalive == 0x01)
{
osd_printf_verbose("M1COMM: rx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;

m_shared[0] = 0xff;
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
osd_printf_verbose("M1COMM: rx connection lost\n");
m_line_rx.reset();
m_line_tx.reset();
}
if (m_linkalive == 0x01)
{
m_linkalive = 0x02;
m_linktimer = 0x00;
m_shared[0] = 0xff;
}
break;
}
return recv;
}
Expand All @@ -623,18 +648,15 @@ void m1comm_device::send_frame(int dataSize){
std::uint32_t written;

filerr = m_line_tx->write(&m_buffer0, 0, dataSize, written);
if (filerr)
if (filerr.value() != 0)
{
osd_printf_verbose("M1COMM: tx connection lost\n");
m_line_tx.reset();
if (m_linkalive == 0x01)
{
osd_printf_verbose("M1COMM: tx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;

m_shared[0] = 0xff;

m_line_rx.reset();
m_line_tx.reset();
}
}
}
Expand Down
54 changes: 41 additions & 13 deletions src/mame/sega/m2comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ void m2comm_device::comm_tick()
{
if (m_linkenable == 0x01)
{
std::error_condition filerr;

int frameStart = 0x2000;
int frameSize = m_shared[0x13] << 8 | m_shared[0x12];
int frameOffset = frameStart | m_shared[0x15] << 8 | m_shared[0x14];
Expand Down Expand Up @@ -374,15 +376,25 @@ void m2comm_device::comm_tick()
{
osd_printf_verbose("M2COMM: listen on %s\n", m_localhost);
uint64_t filesize; // unused
osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
filerr = osd_file::open(m_localhost, OPEN_FLAG_CREATE, m_line_rx, filesize);
if (filerr.value() != 0)
{
osd_printf_verbose("M2COMM: rx connection failed\n");
m_line_rx.reset();
}
}

// check tx socket
if (!m_line_tx)
{
osd_printf_verbose("M2COMM: connect to %s\n", m_remotehost);
uint64_t filesize; // unused
osd_file::open(m_remotehost, 0, m_line_tx, filesize);
filerr = osd_file::open(m_remotehost, 0, m_line_tx, filesize);
if (filerr.value() != 0)
{
osd_printf_verbose("M2COMM: tx connection failed\n");
m_line_tx.reset();
}
}

// if both sockets are there check ring
Expand Down Expand Up @@ -653,22 +665,38 @@ int m2comm_device::read_frame(int dataSize)
togo -= recv;
offset += recv;
}
else if (!filerr && recv == 0)
switch (filerr.value())
{
togo = 0;
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
togo = 0;
break;
}
}
}
}
else if (!filerr && recv == 0)
switch (filerr.value())
{
if (m_linkalive == 0x01)
{
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
osd_printf_verbose("M2COMM: rx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_line_rx.reset();
}
if (m_linkalive == 0x01)
{
m_linkalive = 0x02;
m_linktimer = 0x00;
}
break;
}
return recv;
}
Expand All @@ -691,14 +719,14 @@ void m2comm_device::send_frame(int dataSize){
std::uint32_t written;

filerr = m_line_tx->write(&m_buffer0, 0, dataSize, written);
if (filerr)
if (filerr.value() != 0)
{
osd_printf_verbose("M2COMM: tx connection lost\n");
m_line_tx.reset();
if (m_linkalive == 0x01)
{
osd_printf_verbose("M2COMM: tx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_line_tx.reset();
}
}
}
Expand Down
38 changes: 27 additions & 11 deletions src/mame/sega/s32comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,38 @@ int s32comm_device::read_frame(int dataSize)
togo -= recv;
offset += recv;
}
else if (!filerr && recv == 0)
switch (filerr.value())
{
togo = 0;
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
togo = 0;
break;
}
}
}
}
else if (!filerr && recv == 0)
switch (filerr.value())
{
if (m_linkalive == 0x01)
{
case 0x00:
case 0x8c:
// 00 - no error
// 8c - unknown error (read behind eof?)
break;

default:
osd_printf_verbose("S32COMM: rx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_line_rx.reset();
}
if (m_linkalive == 0x01)
{
m_linkalive = 0x02;
m_linktimer = 0x00;
}
break;
}
return recv;
}
Expand All @@ -326,14 +342,14 @@ void s32comm_device::send_frame(int dataSize){
std::uint32_t written;

filerr = m_line_tx->write(&m_buffer0, 0, dataSize, written);
if (filerr)
if (filerr.value() != 0)
{
osd_printf_verbose("S32COMM: tx connection lost\n");
m_line_tx.reset();
if (m_linkalive == 0x01)
{
osd_printf_verbose("S32COMM: tx connection lost\n");
m_linkalive = 0x02;
m_linktimer = 0x00;
m_line_tx.reset();
}
}
}
Expand Down
Loading

0 comments on commit 3ad5eeb

Please sign in to comment.