trunk/src/osd/modules/netdev/pcap.c
| r249174 | r249175 | |
| 125 | 125 | static void netdev_pcap_handler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes) { |
| 126 | 126 | struct netdev_pcap_context *ctx = (struct netdev_pcap_context*)user; |
| 127 | 127 | |
| 128 | if(!ctx->p) return; |
| 129 | |
| 128 | 130 | if(OSAtomicCompareAndSwapInt((ctx->head+1) & 0x1F, ctx->tail, &ctx->tail)) { |
| 129 | 131 | printf("buffer full, dropping packet\n"); |
| 130 | 132 | return; |
| r249174 | r249175 | |
| 137 | 139 | static void *netdev_pcap_blocker(void *arg) { |
| 138 | 140 | struct netdev_pcap_context *ctx = (struct netdev_pcap_context*)arg; |
| 139 | 141 | |
| 140 | | while(1) { |
| 142 | while(ctx && ctx->p) { |
| 141 | 143 | pcap_dispatch_dl(ctx->p, 1, netdev_pcap_handler, (u_char*)ctx); |
| 142 | 144 | } |
| 143 | 145 | |
| r249174 | r249175 | |
| 232 | 234 | |
| 233 | 235 | netdev_pcap::~netdev_pcap() |
| 234 | 236 | { |
| 237 | #ifdef SDLMAME_MACOSX |
| 238 | m_ctx.p = NULL; |
| 239 | pthread_cancel(m_thread); |
| 240 | pthread_join(m_thread, NULL); |
| 241 | #endif |
| 235 | 242 | if(m_p) pcap_close_dl(m_p); |
| 236 | 243 | m_p = NULL; |
| 237 | 244 | } |