1*4d8b188fSratchov /* $OpenBSD: sock.h,v 1.9 2024/05/24 15:16:09 ratchov Exp $ */ 287bc9f6aSratchov /* 387bc9f6aSratchov * Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org> 487bc9f6aSratchov * 587bc9f6aSratchov * Permission to use, copy, modify, and distribute this software for any 687bc9f6aSratchov * purpose with or without fee is hereby granted, provided that the above 787bc9f6aSratchov * copyright notice and this permission notice appear in all copies. 887bc9f6aSratchov * 987bc9f6aSratchov * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1087bc9f6aSratchov * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1187bc9f6aSratchov * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1287bc9f6aSratchov * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1387bc9f6aSratchov * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1487bc9f6aSratchov * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1587bc9f6aSratchov * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1687bc9f6aSratchov */ 1787bc9f6aSratchov #ifndef SOCK_H 1887bc9f6aSratchov #define SOCK_H 1987bc9f6aSratchov 2087bc9f6aSratchov #include "amsg.h" 2187bc9f6aSratchov 2287bc9f6aSratchov struct file; 2387bc9f6aSratchov struct slot; 2487bc9f6aSratchov struct midi; 2587bc9f6aSratchov 2687bc9f6aSratchov struct sock { 2787bc9f6aSratchov struct sock *next; 2887bc9f6aSratchov int fd; 2987bc9f6aSratchov struct file *file; 3087bc9f6aSratchov struct amsg rmsg, wmsg; /* messages being sent/received */ 3187bc9f6aSratchov unsigned int wmax; /* max bytes we're allowed to write */ 3287bc9f6aSratchov unsigned int rmax; /* max bytes we're allowed to read */ 3387bc9f6aSratchov unsigned int rsize; /* input bytes to read (DATA msg) */ 3487bc9f6aSratchov unsigned int wsize; /* output bytes to write (DATA msg) */ 3587bc9f6aSratchov unsigned int rtodo; /* input bytes not read yet */ 3687bc9f6aSratchov unsigned int wtodo; /* output bytes not written yet */ 3787bc9f6aSratchov #define SOCK_RIDLE 0 /* not expecting messages */ 3887bc9f6aSratchov #define SOCK_RMSG 1 /* expecting a message */ 3987bc9f6aSratchov #define SOCK_RDATA 2 /* data chunk being read */ 4087bc9f6aSratchov #define SOCK_RRET 3 /* reply being returned */ 4187bc9f6aSratchov unsigned int rstate; /* state of the read-end FSM */ 4287bc9f6aSratchov #define SOCK_WIDLE 0 /* nothing to do */ 4387bc9f6aSratchov #define SOCK_WMSG 1 /* amsg being written */ 4487bc9f6aSratchov #define SOCK_WDATA 2 /* data chunk being written */ 4587bc9f6aSratchov unsigned int wstate; /* state of the write-end FSM */ 4687bc9f6aSratchov #define SOCK_AUTH 0 /* waiting for AUTH message */ 4787bc9f6aSratchov #define SOCK_HELLO 1 /* waiting for HELLO message */ 4887bc9f6aSratchov #define SOCK_INIT 2 /* parameter negotiation */ 4987bc9f6aSratchov #define SOCK_START 3 /* filling play buffers */ 5087bc9f6aSratchov #define SOCK_STOP 4 /* draining rec buffers */ 5187bc9f6aSratchov unsigned int pstate; /* one of the above */ 5287bc9f6aSratchov int tickpending; /* tick waiting to be transmitted */ 5387bc9f6aSratchov int fillpending; /* flowctl waiting to be transmitted */ 5487bc9f6aSratchov int stoppending; /* last STOP ack to be sent */ 5587bc9f6aSratchov unsigned int walign; /* align written data to this */ 5687bc9f6aSratchov unsigned int ralign; /* read data is aligned to this */ 5787bc9f6aSratchov int lastvol; /* last volume */ 5887bc9f6aSratchov struct slot *slot; /* audio device slot number */ 599fd7fddfSratchov struct midi *midi; /* midi endpoint */ 609fd7fddfSratchov struct port *port; /* midi port */ 61d07fece6Sratchov struct ctlslot *ctlslot; 623e5ee6d4Sratchov unsigned char *ctldesc; /* temporary buffer */ 63*4d8b188fSratchov size_t ctl_desc_size; /* size of client amsg_ctl_desc */ 64d07fece6Sratchov #define SOCK_CTLDESC 1 /* dump desc and send changes */ 65d07fece6Sratchov #define SOCK_CTLVAL 2 /* send value changes */ 66d07fece6Sratchov unsigned int ctlops; /* bitmap of above */ 67d07fece6Sratchov int ctlsyncpending; /* CTLSYNC waiting to be transmitted */ 6872ca3e97Sratchov unsigned int sesrefs; /* 1 if socket belongs to a session */ 6987bc9f6aSratchov }; 7087bc9f6aSratchov 7187bc9f6aSratchov struct sock *sock_new(int fd); 7287bc9f6aSratchov void sock_close(struct sock *); 7387bc9f6aSratchov extern struct sock *sock_list; 7487bc9f6aSratchov 7587bc9f6aSratchov #endif /* !defined(SOCK_H) */ 76