mirror of
https://github.com/mamedev/mame.git
synced 2024-11-18 10:06:19 +01:00
netdev: fix race condition/crash when using the OSD to choose pcap devices. [Rob Braun]
This commit is contained in:
parent
793271786e
commit
140163dcc7
3 changed files with 22 additions and 4 deletions
|
@ -189,7 +189,14 @@ void netdev_pcap::set_mac(const char *mac)
|
|||
|
||||
int netdev_pcap::send(UINT8 *buf, int len)
|
||||
{
|
||||
if(!m_p) return 0;
|
||||
int ret;
|
||||
if(!m_p) {
|
||||
printf("send invoked, but no pcap context\n");
|
||||
return 0;
|
||||
}
|
||||
ret = pcap_sendpacket_dl(m_p, buf, len);
|
||||
printf("sent packet length %d, returned %d\n", len, ret);
|
||||
return ret ? len : 0;
|
||||
return (!pcap_sendpacket_dl(m_p, buf, len))?len:0;
|
||||
}
|
||||
|
||||
|
@ -219,6 +226,7 @@ int netdev_pcap::recv_dev(UINT8 **buf)
|
|||
netdev_pcap::~netdev_pcap()
|
||||
{
|
||||
if(m_p) pcap_close_dl(m_p);
|
||||
m_p = NULL;
|
||||
}
|
||||
|
||||
static CREATE_NETDEV(create_pcap)
|
||||
|
@ -279,7 +287,11 @@ int pcap_module::init()
|
|||
|
||||
while(devs)
|
||||
{
|
||||
if(devs->description) {
|
||||
add_netdev(devs->name, devs->description, create_pcap);
|
||||
} else {
|
||||
add_netdev(devs->name, devs->name, create_pcap);
|
||||
}
|
||||
devs = devs->next;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -39,11 +39,15 @@ class osd_netdev *open_netdev(int id, class device_network_interface *ifdev, int
|
|||
osd_netdev::osd_netdev(class device_network_interface *ifdev, int rate)
|
||||
{
|
||||
m_dev = ifdev;
|
||||
ifdev->device().machine().scheduler().timer_pulse(attotime::from_hz(rate), timer_expired_delegate(FUNC(osd_netdev::recv), this));
|
||||
m_stop = false;
|
||||
m_timer = ifdev->device().machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(osd_netdev::recv), this));
|
||||
m_timer->adjust(attotime::from_hz(rate), 0, attotime::from_hz(rate));
|
||||
}
|
||||
|
||||
osd_netdev::~osd_netdev()
|
||||
{
|
||||
m_stop = true;
|
||||
m_timer->reset();
|
||||
}
|
||||
|
||||
int osd_netdev::send(UINT8 *buf, int len)
|
||||
|
@ -56,7 +60,7 @@ void osd_netdev::recv(void *ptr, int param)
|
|||
UINT8 *buf;
|
||||
int len;
|
||||
//const char atalkmac[] = { 0x09, 0x00, 0x07, 0xff, 0xff, 0xff };
|
||||
while((len = recv_dev(&buf)))
|
||||
while((!m_stop) && (len = recv_dev(&buf)))
|
||||
{
|
||||
#if 0
|
||||
if(buf[0] & 1)
|
||||
|
|
|
@ -36,6 +36,8 @@ private:
|
|||
void recv(void *ptr, int param);
|
||||
|
||||
class device_network_interface *m_dev;
|
||||
emu_timer *m_timer;
|
||||
bool m_stop;
|
||||
};
|
||||
|
||||
class osd_netdev *open_netdev(int id, class device_network_interface *ifdev, int rate);
|
||||
|
|
Loading…
Reference in a new issue