| Previous | 15994 Revisions | Next |
| r13340 Tuesday 22nd November, 2011 at 11:27:19 UTC by Miodrag Milanović |
|---|
| Fixed memory leaks in networking, used core functions for allocating memory, fix sdl win32 building with network enabled (no whatsnew) |
| [src/osd] | osdnet.c osdnet.h |
| [src/osd/sdl] | netdev.c netdev.h netdev_pcap.c netdev_pcap.h netdev_tap.c netdev_tap.h sdl.mak sdlmain.c |
| [src/osd/windows] | netdev.c netdev.h netdev_pcap.c netdev_pcap.h winmain.c |
| r13339 | r13340 | |
|---|---|---|
| 30 | 30 | |
| 31 | 31 | class netdev *open_netdev(int id, class device_network_interface *ifdev, int rate); |
| 32 | 32 | void add_netdev(const char *name, create_netdev func); |
| 33 | void clear_netdev(); | |
| 33 | 34 | #endif |
| r13339 | r13340 | |
|---|---|---|
| 518 | 518 | $(SDLOBJ)/netdev_pcap.o |
| 519 | 519 | |
| 520 | 520 | DEFS += -DSDLMAME_NETWORK -DSDLMAME_NET_PCAP |
| 521 | ifneq ($(TARGETOS),win32) | |
| 521 | 522 | LIBS += -lpcap |
| 522 | 523 | endif |
| 523 | 524 | endif |
| 525 | endif | |
| 524 | 526 | |
| 525 | 527 | #------------------------------------------------- |
| 526 | 528 | # Dependencies |
| r13339 | r13340 | |
|---|---|---|
| 70 | 70 | |
| 71 | 71 | static CREATE_NETDEV(create_pcap) |
| 72 | 72 | { |
| 73 | class netdev_pcap *dev = ne | |
| 73 | class netdev_pcap *dev = global_alloc(ne | |
| 74 | 74 | return dynamic_cast<netdev *>(dev); |
| 75 | 75 | } |
| 76 | 76 | |
| r13339 | r13340 | |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | void deinit_pcap() | |
| 98 | { | |
| 99 | clear_netdev(); | |
| 100 | } | |
| 101 | ||
| 97 | 102 | #endif // SDLMAME_WIN32 |
| r13339 | r13340 | |
|---|---|---|
| 88 | 88 | |
| 89 | 89 | static CREATE_NETDEV(create_tap) |
| 90 | 90 | { |
| 91 | class netdev_tap *dev = ne | |
| 91 | class netdev_tap *dev = global_alloc(ne | |
| 92 | 92 | return dynamic_cast<netdev *>(dev); |
| 93 | 93 | } |
| 94 | 94 | |
| r13339 | r13340 | |
| 96 | 96 | { |
| 97 | 97 | add_netdev("tap", create_tap); |
| 98 | 98 | } |
| 99 | ||
| 100 | void deinit_tap() | |
| 101 | { | |
| 102 | clear_netdev(); | |
| 103 | } | |
| No newline at end of file |
| r13339 | r13340 | |
|---|---|---|
| 2 | 2 | #define __NETDEV_PCAP_H__ |
| 3 | 3 | |
| 4 | 4 | void init_pcap(); |
| 5 | void deinit_pcap(); | |
| 5 | 6 | |
| 6 | 7 | #endif |
| r13339 | r13340 | |
|---|---|---|
| 2 | 2 | #define __NETDEV_TAP_H__ |
| 3 | 3 | |
| 4 | 4 | void init_tap(); |
| 5 | ||
| 5 | void deinit_tap(); | |
| 6 | 6 | #endif |
| r13339 | r13340 | |
|---|---|---|
| 11 | 11 | init_pcap(); |
| 12 | 12 | #endif |
| 13 | 13 | } |
| 14 | ||
| 15 | void sdlnetdev_deinit(running_machine &machine) | |
| 16 | { | |
| 17 | #ifdef SDLMAME_NET_TAPTUN | |
| 18 | deinit_tap(); | |
| 19 | #endif | |
| 20 | #ifdef SDLMAME_NET_PCAP | |
| 21 | deinit_pcap(); | |
| 22 | #endif | |
| 23 | } |
| r13339 | r13340 | |
|---|---|---|
| 409 | 409 | |
| 410 | 410 | void sdl_osd_interface::osd_exit(running_machine &machine) |
| 411 | 411 | { |
| 412 | #ifdef SDLMAME_NETWORK | |
| 413 | sdlnetdev_deinit(machine); | |
| 414 | #endif | |
| 412 | 415 | |
| 413 | 416 | if (!SDLMAME_INIT_IN_WORKER_THREAD) |
| 414 | 417 | SDL_Quit(); |
| r13339 | r13340 | |
|---|---|---|
| 2 | 2 | #define __NETDEV_H__ |
| 3 | 3 | |
| 4 | 4 | void sdlnetdev_init(running_machine &machine); |
| 5 | void sdlnetdev_deinit(running_machine &machine); | |
| 5 | 6 | |
| 6 | 7 | #endif |
| r13339 | r13340 | |
|---|---|---|
| 78 | 78 | |
| 79 | 79 | static CREATE_NETDEV(create_pcap) |
| 80 | 80 | { |
| 81 | class netdev_pcap *dev = ne | |
| 81 | class netdev_pcap *dev = global_alloc(ne | |
| 82 | 82 | return dynamic_cast<netdev *>(dev); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | static HMODULE handle = NULL; | |
| 86 | ||
| 85 | 87 | void init_pcap() |
| 86 | 88 | { |
| 87 | 89 | pcap_if_t *devs; |
| 88 | 90 | char errbuf[PCAP_ERRBUF_SIZE]; |
| 89 | | |
| 91 | | |
| 90 | 92 | |
| 91 | 93 | try |
| 92 | 94 | { |
| r13339 | r13340 | |
| 120 | 122 | mame_printf_verbose("Unable to get network devices: %s\n", errbuf); |
| 121 | 123 | return; |
| 122 | 124 | } |
| 123 | while(devs->next) | |
| 125 | ||
| 126 | if (devs) | |
| 124 | 127 | { |
| 125 | add_netdev(devs->name, create_pcap); | |
| 126 | devs = devs->next; | |
| 128 | while(devs->next) | |
| 129 | { | |
| 130 | add_netdev(devs->name, create_pcap); | |
| 131 | devs = devs->next; | |
| 132 | } | |
| 127 | 133 | } |
| 128 | 134 | } |
| 135 | ||
| 136 | void deinit_pcap() | |
| 137 | { | |
| 138 | clear_netdev(); | |
| 139 | FreeLibrary(handle); | |
| 140 | } | |
| 141 |
| r13339 | r13340 | |
|---|---|---|
| 2 | 2 | #define __NETDEV_H |
| 3 | 3 | |
| 4 | 4 | void init_pcap(); |
| 5 | void deinit_pcap(); | |
| 5 | 6 | |
| 6 | 7 | #endif |
| r13339 | r13340 | |
|---|---|---|
| 709 | 709 | // cleanup sockets |
| 710 | 710 | win_cleanup_sockets(); |
| 711 | 711 | |
| 712 | #ifdef USE_NETWORK | |
| 713 | winnetdev_deinit(machine); | |
| 714 | #endif | |
| 715 | ||
| 712 | 716 | // take down the watchdog thread if it exists |
| 713 | 717 | if (watchdog_thread != NULL) |
| 714 | 718 | { |
| r13339 | r13340 | |
|---|---|---|
| 5 | 5 | { |
| 6 | 6 | init_pcap(); |
| 7 | 7 | } |
| 8 | ||
| 9 | void winnetdev_deinit(running_machine &machine) | |
| 10 | { | |
| 11 | deinit_pcap(); | |
| 12 | } |
| r13339 | r13340 | |
|---|---|---|
| 2 | 2 | #define __NETDEV_H |
| 3 | 3 | |
| 4 | 4 | void winnetdev_init(running_machine &machine); |
| 5 | void winnetdev_deinit(running_machine &machine); | |
| 5 | 6 | |
| 6 | 7 | #endif |
| r13339 | r13340 | |
|---|---|---|
| 13 | 13 | |
| 14 | 14 | void add_netdev(const char *name, create_netdev func) |
| 15 | 15 | { |
| 16 | netdev_entry_t *entry = | |
| 16 | netdev_entry_t *entry = global_alloc_clear(netdev_entry_t); | |
| 17 | 17 | entry->id = netdev_list.count(); |
| 18 | 18 | strncpy(entry->name, name, 255); |
| 19 | 19 | entry->name[255] = '\0'; |
| r13339 | r13340 | |
| 21 | 21 | netdev_list.append(*entry); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | void clear_netdev() | |
| 25 | { | |
| 26 | netdev_list.reset(); | |
| 27 | } | |
| 28 | ||
| 24 | 29 | class netdev *open_netdev(int id, class device_network_interface *ifdev, int rate) |
| 25 | 30 | { |
| 26 | 31 | netdev_entry_t *entry = netdev_list.first(); |
| Previous | 15994 Revisions | Next |