186
void slirp_select_fill(int *pnfds,
187
fd_set *readfds, fd_set *writefds, fd_set *xfds)
186
int slirp_select_fill(int *pnfds,
187
fd_set *readfds, fd_set *writefds, fd_set *xfds)
189
189
struct socket *so, *so_next;
190
struct timeval timeout;
191
int timeout, tmp_time;
195
194
global_readfds = NULL;
301
300
* Setup timeout to use minimum CPU usage, especially when idle
305
* First, see the timeout needed by *timo
308
timeout.tv_usec = -1;
310
* If a slowtimo is needed, set timeout to 500ms from the last
306
* If a slowtimo is needed, set timeout to 5ms from the last
311
307
* slow timeout. If a fast timeout is needed, set timeout within
312
* 200ms of when it was requested.
308
* 2ms of when it was requested.
314
312
if (do_slowtimo) {
315
/* XXX + 10000 because some select()'s aren't that accurate */
316
timeout.tv_usec = ((500 - (curtime - last_slowtimo)) * 1000) + 10000;
317
if (timeout.tv_usec < 0)
319
else if (timeout.tv_usec > 510000)
320
timeout.tv_usec = 510000;
313
timeout = (SLOW_TIMO - (curtime - last_slowtimo)) * 1000;
316
else if (timeout > (SLOW_TIMO * 1000))
317
timeout = SLOW_TIMO * 1000;
322
319
/* Can only fasttimo if we also slowtimo */
323
320
if (time_fasttimo) {
324
tmp_time = (200 - (curtime - time_fasttimo)) * 1000;
321
tmp_time = (FAST_TIMO - (curtime - time_fasttimo)) * 1000;
325
322
if (tmp_time < 0)
328
325
/* Choose the smallest of the 2 */
329
if (tmp_time < timeout.tv_usec)
330
timeout.tv_usec = (u_int)tmp_time;
326
if (tmp_time < timeout)
333
* Adjust the timeout to make the minimum timeout
334
* 2ms (XXX?) to lessen the CPU load
336
if (timeout < (FAST_TIMO * 1000))
337
timeout = FAST_TIMO * 1000;
336
342
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
349
355
* See if anything has timed out
352
if (time_fasttimo && ((curtime - time_fasttimo) >= 199)) {
358
if (time_fasttimo && ((curtime - time_fasttimo) >= FAST_TIMO)) {
354
360
time_fasttimo = 0;
356
if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
362
if (do_slowtimo && ((curtime - last_slowtimo) >= SLOW_TIMO)) {
359
365
last_slowtimo = curtime;
608
memcpy(m->m_data, pkt, pkt_len);
613
/* Note: we add to align the IP header */
614
m->m_len = pkt_len + 2;
615
memcpy(m->m_data + 2, pkt, pkt_len);
610
m->m_data += ETH_HLEN;
611
m->m_len -= ETH_HLEN;
617
m->m_data += 2 + ETH_HLEN;
618
m->m_len -= 2 + ETH_HLEN;