1/* $OpenBSD: aucat.h,v 1.8 2019/07/05 22:53:47 ratchov Exp $ */ 2/* 3 * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18#ifndef AUCAT_H 19#define AUCAT_H 20 21#include "amsg.h" 22 23struct aucat { 24 int fd; /* socket */ 25 struct amsg rmsg, wmsg; /* temporary messages */ 26 size_t wtodo, rtodo; /* bytes to complete the packet */ 27#define RSTATE_MSG 0 /* message being received */ 28#define RSTATE_DATA 1 /* data being received */ 29 unsigned rstate; /* one of above */ 30#define WSTATE_IDLE 2 /* nothing to do */ 31#define WSTATE_MSG 3 /* message being transferred */ 32#define WSTATE_DATA 4 /* data being transferred */ 33 unsigned wstate; /* one of above */ 34 unsigned maxwrite; /* bytes we're allowed to write */ 35}; 36 37int _aucat_rmsg(struct aucat *, int *); 38int _aucat_wmsg(struct aucat *, int *); 39size_t _aucat_rdata(struct aucat *, void *, size_t, int *); 40size_t _aucat_wdata(struct aucat *, const void *, size_t, unsigned, int *); 41int _aucat_open(struct aucat *, const char *, unsigned); 42void _aucat_close(struct aucat *, int); 43int _aucat_pollfd(struct aucat *, struct pollfd *, int); 44int _aucat_revents(struct aucat *, struct pollfd *); 45int _aucat_setfl(struct aucat *, int, int *); 46 47#endif /* !defined(AUCAT_H) */ 48