449
447
* then read as many events as possible (but at least 1) and enqueue them
453
register AuServer *aud;
450
_AuReadEvents(register AuServer *aud)
455
_AuAlignedBuffer buf;
458
register auReply *rep;
459
AuBool not_yet_flushed = AuTrue;
462
/* find out how much data can be read */
463
if (BytesReadable(aud->fd, (char *) &pend) < 0)
467
/* must read at least one auEvent; if none is pending, then
468
we'll just flush and block waiting for it */
469
if (len < SIZEOF(auEvent)) {
470
len = SIZEOF(auEvent);
471
/* don't flush until we block the first time */
472
if (not_yet_flushed) {
473
int qlen = aud->qlen;
475
if (qlen != aud->qlen) return;
476
not_yet_flushed = AuFalse;
480
/* but we won't read more than the max buffer size */
484
/* round down to an integral number of AuReps */
485
len = (len / SIZEOF(auEvent)) * SIZEOF(auEvent);
487
_AuRead (aud, buf.buf, (AuInt32) len);
489
STARTITERATE(rep,auReply,buf.buf,len > 0) {
490
if (rep->generic.type == Au_Reply) {
492
RESETITERPTR(rep,auReply,
493
_AuAsyncReply (aud, rep,
494
ITERPTR(rep), &pend, AuTrue));
497
if (rep->generic.type == Au_Error)
498
_AuError (aud, (auError *) rep);
499
else /* must be an event packet */
500
_AuEnq (aud, (auEvent *)rep, AuEventEnqueuedByUnknown);
501
INCITERPTR(rep,auReply);
502
len -= SIZEOF(auReply);
505
} while (aud->head == NULL);
452
_AuAlignedBuffer buf;
455
register auReply *rep;
456
AuBool not_yet_flushed = AuTrue;
458
/* lock read access to the server */
459
_AuLockMutex(_rev_mutex);
462
/* find out how much data can be read */
463
if (BytesReadable(aud->fd, (char *) &pend) < 0)
467
/* must read at least one auEvent; if none is pending, then
468
we'll just flush and block waiting for it */
469
if (len < SIZEOF(auEvent)) {
470
len = SIZEOF(auEvent);
471
/* don't flush until we block the first time */
472
if (not_yet_flushed) {
473
int qlen = aud->qlen;
475
if (qlen != aud->qlen) return;
476
not_yet_flushed = AuFalse;
480
/* but we won't read more than the max buffer size */
484
/* round down to an integral number of AuReps */
485
len = (len / SIZEOF(auEvent)) * SIZEOF(auEvent);
487
_AuRead (aud, buf.buf, (AuInt32) len);
489
STARTITERATE(rep,auReply,buf.buf,len > 0) {
490
if (rep->generic.type == Au_Reply) {
492
RESETITERPTR(rep,auReply,
493
_AuAsyncReply (aud, rep,
494
ITERPTR(rep), &pend, AuTrue));
497
if (rep->generic.type == Au_Error)
498
_AuError (aud, (auError *) rep);
499
else /* must be an event packet */
500
_AuEnq (aud, (auEvent *)rep, AuEventEnqueuedByUnknown);
501
INCITERPTR(rep,auReply);
502
len -= SIZEOF(auReply);
505
} while (aud->head == NULL);
507
_AuUnlockMutex(_rev_mutex);
914
894
* _AuReply - Wait for a reply packet and copy its contents into the
915
895
* specified rep. Mean while we must handle error and event packets that
916
896
* we may encounter.
898
* int extra; number of 32-bit words expected after the reply
899
* AuBool discard; should I discard data following "extra" words?
918
AuBool _AuReply (aud, rep, extra, discard, ret_status)
919
register AuServer *aud;
920
register auReply *rep;
921
int extra; /* number of 32-bit words expected after the reply */
922
AuBool discard; /* should I discard data following "extra" words? */
923
AuStatus *ret_status;
901
AuBool _AuReply (register AuServer *aud, register auReply *rep,
902
int extra, AuBool discard, AuStatus *ret_status)
925
904
/* Pull out the serial number now, so that (currently illegal) requests
926
905
* generated by an error handler don't confuse us.
1102
1077
* error_code, major, and minor all to 0 to catch all errors.
1105
_AuForceRoundTrip (aud, error_code, majorop, minorop, ret_status)
1110
AuStatus *ret_status;
1080
_AuForceRoundTrip (AuServer *aud, int error_code, int majorop, int minorop,
1081
AuStatus *ret_status)
1112
1083
AuUint32 seq = aud->request; /* get previous request */
1113
1084
auGetCloseDownModeReply rep;
1184
AuUnregisterEventEnqHandler(aud, handler)
1186
AuEventEnqHandlerRec *handler;
1151
AuUnregisterEventEnqHandler(AuServer *aud, AuEventEnqHandlerRec *handler)
1188
1153
_AuRemoveFromLinkedList(aud->eventenqhandlerq, handler);
1189
1154
Aufree(handler);
1193
_AuEventEnqueued(aud, who, event)
1158
_AuEventEnqueued(AuServer *aud, int who, AuEvent *event)
1198
1160
AuEventEnqHandlerRec *p = aud->eventenqhandlerq,
1248
1207
* EventToWire in separate file in that often not needed.
1209
* AuServer *aud; pointer to server structure
1210
* AuEvent *re; pointer to where event should be reformatted
1211
* auEvent *event; wire protocol event
1253
_AuUnknownWireEvent(aud, re, event)
1254
register AuServer *aud; /* pointer to server structure */
1255
register AuEvent *re; /* pointer to where event should be reformatted */
1256
register auEvent *event; /* wire protocol event */
1216
_AuUnknownWireEvent(register AuServer *aud, register AuEvent *re,
1217
register auEvent *event)
1259
1220
(void) fprintf(stderr,
1281
1240
* reformat a wire event into an AuEvent structure of the right type.
1284
_AuWireToEvent(aud, re, event)
1285
register AuServer *aud; /* pointer to server
1287
register AuEvent *re; /* pointer to where event
1288
* should be reformatted */
1289
register auEvent *event; /* wire protocol event */
1243
_AuWireToEvent(register AuServer *aud, register AuEvent *re,
1244
register auEvent *event)
1292
1247
re->type = event->u.u.type & 0x7f;
1561
1499
* audiolib routine for scratch space. It is reallocated from the same place
1562
1500
* each time, unless the library needs a large scratch space.
1564
char *_AuAllocScratch (aud, nbytes)
1565
register AuServer *aud;
1502
char *_AuAllocScratch (register AuServer *aud, AuUint32 nbytes)
1568
1504
if (nbytes > aud->scratch_length) {
1569
if (aud->scratch_buffer) Aufree (aud->scratch_buffer);
1570
if ((aud->scratch_buffer = Aumalloc((unsigned) nbytes)) != NULL)
1571
aud->scratch_length = nbytes;
1505
if (aud->scratch_buffer) Aufree ((void *)aud->scratch_buffer);
1506
if ((aud->scratch_buffer =
1507
(char *)Aumalloc((unsigned) nbytes)) != NULL)
1508
aud->scratch_length = nbytes;
1572
1509
else aud->scratch_length = 0;
1574
return (aud->scratch_buffer);
1511
return ((char *)aud->scratch_buffer);
1516
AuFree (AuPointer data)
1585
1521
#ifdef _AUNEEDBCOPYFUNC
1586
void _Aubcopy(b1, b2, length)
1587
register char *b1, *b2;
1522
void _Aubcopy(register char *b1, register char *b2, register int length)
1820
1735
#include <sys/socket.h>
1822
int _AuReadV (fd, iov, iovcnt)
1737
int _AuReadV (int fd, struct iovec *iov, int iovcnt)
1830
hdr.msg_iovlen = iovcnt;
1831
hdr.msg_accrights = 0;
1832
hdr.msg_accrightslen = 0;
1834
hdr.msg_namelen = 0;
1836
return (recvmsg (fd, &hdr, 0));
1742
hdr.msg_iovlen = iovcnt;
1743
hdr.msg_accrights = 0;
1744
hdr.msg_accrightslen = 0;
1746
hdr.msg_namelen = 0;
1748
return (recvmsg (fd, &hdr, 0));
1839
int _AuWriteV (fd, iov, iovcnt)
1751
int _AuWriteV (int fd, struct iovec *iov, int iovcnt)
1847
hdr.msg_iovlen = iovcnt;
1848
hdr.msg_accrights = 0;
1849
hdr.msg_accrightslen = 0;
1851
hdr.msg_namelen = 0;
1853
return (sendmsg (fd, &hdr, 0));
1756
hdr.msg_iovlen = iovcnt;
1757
hdr.msg_accrights = 0;
1758
hdr.msg_accrightslen = 0;
1760
hdr.msg_namelen = 0;
1762
return (sendmsg (fd, &hdr, 0));
1856
1765
#endif /* CRAY */
1864
1773
#include <sys/uio.h>
1865
1774
#endif /* !WIN32 */
1867
int _AuReadV (fd, iov, iovcnt)
1776
int _AuReadV (int fd, struct iovec *iov, int iovcnt)
1876
for (i=0, total=0; i<iovcnt; i++, iov++) {
1878
base = iov->iov_base;
1880
register int nbytes;
1782
for (i=0, total=0; i<iovcnt; i++, iov++) {
1784
base = iov->iov_base;
1786
register int nbytes;
1882
nbytes = read(fd, base, len);
1788
nbytes = read(fd, base, len);
1883
1789
#else /* WIN32 */
1884
nbytes = recv(fd, base, len, 0);
1790
nbytes = recv(fd, base, len, 0);
1885
1791
#endif /* WIN32 */
1886
if (nbytes < 0 && total == 0) return -1;
1887
if (nbytes <= 0) return total;
1792
if (nbytes < 0 && total == 0) return -1;
1793
if (nbytes <= 0) return total;
1898
int _AuWriteV (fd, iov, iovcnt)
1804
int _AuWriteV (int fd, struct iovec *iov, int iovcnt)
1907
for (i=0, total=0; i<iovcnt; i++, iov++) {
1909
base = iov->iov_base;
1911
register int nbytes;
1912
nbytes = send(fd, base, len, 0);
1913
if (nbytes < 0 && total == 0) return -1;
1914
if (nbytes <= 0) return total;
1810
for (i=0, total=0; i<iovcnt; i++, iov++) {
1812
base = iov->iov_base;
1814
register int nbytes;
1815
nbytes = send(fd, base, len, 0);
1816
if (nbytes < 0 && total == 0) return -1;
1817
if (nbytes <= 0) return total;
1923
1826
#endif /* WIN32 */
1880
_AuReadV (int fd, struct iovec v[], int n)
1982
int i, rc, len, size = 0;
1983
char * buf = workarea;
1986
if (n <= 0 || n > 16)
1991
for (i = 0; i < n; ++i)
1993
if ((len = v[i].iov_len) < 0 || v[i].iov_base == NULL)
2000
if ((size > MAX_WORKAREA) && ((buf = malloc (size)) == NULL))
2005
if((rc = (*_AusStream[_AusTypeOfStream[fd]].ReadFromStream)(fd, buf, size,
2008
for (i = 0, p = buf; i < n; ++i)
2010
memcpy (v[i].iov_base, p, len = v[i].iov_len);
2014
if (size > MAX_WORKAREA)
1882
int i, rc, len, size = 0;
1883
char * buf = workarea;
1886
if (n <= 0 || n > 16)
1891
for (i = 0; i < n; ++i)
1893
if ((len = v[i].iov_len) < 0 || v[i].iov_base == NULL)
1900
if ((size > MAX_WORKAREA) && ((buf = malloc (size)) == NULL))
1905
if((rc = (*_AusStream[_AusTypeOfStream[fd]].ReadFromStream)(fd, buf, size,
1908
for (i = 0, p = buf; i < n; ++i)
1910
memcpy (v[i].iov_base, p, len = v[i].iov_len);
1914
if (size > MAX_WORKAREA)
2021
_AuWriteV (fd, v, n)
1921
_AuWriteV (int fd, struct iovec v[], int n)
2026
int i, rc, len, size = 0;
2027
char * buf = workarea;
2030
if (n <= 0 || n > 16)
2035
for (i = 0; i < n; ++i)
2037
if ((len = v[i].iov_len) < 0 || v[i].iov_base == NULL)
2045
if ((size > MAX_WORKAREA) && ((buf = malloc (size)) == NULL))
2050
for (i = 0, p = buf; i < n; ++i)
2052
memcpy (p, v[i].iov_base, len = v[i].iov_len);
2055
rc = (*_AusStream[_AusTypeOfStream[fd]].WriteToStream)(fd, buf, size);
2057
if (size > MAX_WORKAREA)
1923
int i, rc, len, size = 0;
1924
char * buf = workarea;
1927
if (n <= 0 || n > 16)
1932
for (i = 0; i < n; ++i)
1934
if ((len = v[i].iov_len) < 0 || v[i].iov_base == NULL)
1942
if ((size > MAX_WORKAREA) && ((buf = malloc (size)) == NULL))
1947
for (i = 0, p = buf; i < n; ++i)
1949
memcpy (p, v[i].iov_base, len = v[i].iov_len);
1952
rc = (*_AusStream[_AusTypeOfStream[fd]].WriteToStream)(fd, buf, size);
1954
if (size > MAX_WORKAREA)
2067
1964
#ifndef HAS_FAKE_IOV
1966
_AuReadV (int fd, struct iovec v[], int n)
2074
return(readv(fd, v, n));
1968
return(readv(fd, v, n));
2078
_AuWriteV (fd, v, n)
1972
_AuWriteV (int fd, struct iovec v[], int n)
2083
return(writev(fd, v, n));
1974
return(writev(fd, v, n));
2085
1976
#endif /* HAS_FAKE_IOV */
2087
1978
AuSyncHandlerRec *
2088
AuRegisterSyncHandler(aud, callback, data)
2090
AuSyncHandlerCallback callback;
1979
AuRegisterSyncHandler(AuServer *aud, AuSyncHandlerCallback callback,
2093
1982
AuSyncHandlerRec *handler;