sys_generic.c (de7201225514f33f0fde51cab02f4a86c879b13d) sys_generic.c (2e564269d0af3703815a10effe03c1f1773c9a46)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 1460 unchanged lines hidden (view full) ---

1469sys_openbsd_poll(td, uap)
1470 register struct thread *td;
1471 register struct openbsd_poll_args *uap;
1472{
1473 return (sys_poll(td, (struct poll_args *)uap));
1474}
1475
1476/*
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 1460 unchanged lines hidden (view full) ---

1469sys_openbsd_poll(td, uap)
1470 register struct thread *td;
1471 register struct openbsd_poll_args *uap;
1472{
1473 return (sys_poll(td, (struct poll_args *)uap));
1474}
1475
1476/*
1477 * XXX This was created specifically to support netncp and netsmb. This
1478 * allows the caller to specify a socket to wait for events on. It returns
1479 * 0 if any events matched and an error otherwise. There is no way to
1480 * determine which events fired.
1481 */
1482int
1483selsocket(struct socket *so, int events, struct timeval *tvp, struct thread *td)
1484{
1485 struct timeval atv, rtv, ttv;
1486 int error, timo;
1487
1488 if (tvp != NULL) {
1489 atv = *tvp;
1490 if (itimerfix(&atv))
1491 return (EINVAL);
1492 getmicrouptime(&rtv);
1493 timevaladd(&atv, &rtv);
1494 } else {
1495 atv.tv_sec = 0;
1496 atv.tv_usec = 0;
1497 }
1498
1499 timo = 0;
1500 seltdinit(td);
1501 /*
1502 * Iterate until the timeout expires or the socket becomes ready.
1503 */
1504 for (;;) {
1505 selfdalloc(td, NULL);
1506 error = sopoll(so, events, NULL, td);
1507 /* error here is actually the ready events. */
1508 if (error)
1509 return (0);
1510 if (atv.tv_sec || atv.tv_usec) {
1511 getmicrouptime(&rtv);
1512 if (timevalcmp(&rtv, &atv, >=)) {
1513 seltdclear(td);
1514 return (EWOULDBLOCK);
1515 }
1516 ttv = atv;
1517 timevalsub(&ttv, &rtv);
1518 timo = ttv.tv_sec > 24 * 60 * 60 ?
1519 24 * 60 * 60 * hz : tvtohz(&ttv);
1520 }
1521 error = seltdwait(td, timo);
1522 seltdclear(td);
1523 if (error)
1524 break;
1525 }
1526 /* XXX Duplicates ncp/smb behavior. */
1527 if (error == ERESTART)
1528 error = 0;
1529 return (error);
1530}
1531
1532/*
1533 * Preallocate two selfds associated with 'cookie'. Some fo_poll routines
1534 * have two select sets, one for read and another for write.
1535 */
1536static void
1537selfdalloc(struct thread *td, void *cookie)
1538{
1539 struct seltd *stp;
1540

--- 230 unchanged lines hidden ---
1477 * Preallocate two selfds associated with 'cookie'. Some fo_poll routines
1478 * have two select sets, one for read and another for write.
1479 */
1480static void
1481selfdalloc(struct thread *td, void *cookie)
1482{
1483 struct seltd *stp;
1484

--- 230 unchanged lines hidden ---