2009-05-19 20:57:50 +00:00
|
|
|
/*
|
|
|
|
* uhub - A tiny ADC p2p connection hub
|
2010-01-19 13:53:47 +00:00
|
|
|
* Copyright (C) 2007-2010, Jan Vidar Krey
|
2009-05-19 20:57:50 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_UHUB_HUB_IO_H
|
|
|
|
#define HAVE_UHUB_HUB_IO_H
|
|
|
|
|
2009-05-26 17:46:51 +00:00
|
|
|
struct adc_message;
|
|
|
|
struct linked_list;
|
|
|
|
typedef int (*hub_recvq_write)(void* desc, const void* buf, size_t len);
|
|
|
|
typedef int (*hub_recvq_read)(void* desc, void* buf, size_t len);
|
|
|
|
|
|
|
|
struct hub_sendq
|
|
|
|
{
|
|
|
|
size_t size; /** Size of send queue (in bytes, not messages) */
|
|
|
|
size_t offset; /** Queue byte offset in the first message. Should be 0 unless a partial write. */
|
2009-06-22 23:56:37 +00:00
|
|
|
#ifdef SSL_SUPPORT
|
2009-06-25 20:05:40 +00:00
|
|
|
size_t last_send; /** When using SSL, one have to send the exact same buffer and length if a write cannot complete. */
|
2009-06-22 23:56:37 +00:00
|
|
|
#endif
|
2009-05-26 17:46:51 +00:00
|
|
|
struct linked_list* queue; /** List of queued messages */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hub_recvq
|
2009-05-19 20:57:50 +00:00
|
|
|
{
|
|
|
|
char* buf;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
2009-05-26 17:46:51 +00:00
|
|
|
/**
|
|
|
|
* Create a send queue
|
|
|
|
*/
|
|
|
|
extern struct hub_sendq* hub_sendq_create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy a send queue, and delete any queued messages.
|
|
|
|
*/
|
|
|
|
extern void hub_sendq_destroy(struct hub_sendq*);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a message to the send queue.
|
|
|
|
*/
|
|
|
|
extern void hub_sendq_add(struct hub_sendq*, struct adc_message* msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the send queue, and send as many messages as possible.
|
2009-10-07 15:37:31 +00:00
|
|
|
* @returns -1 on error, 0 if unable to send more, 1 if more can be sent.
|
2009-05-26 17:46:51 +00:00
|
|
|
*/
|
2009-10-07 15:37:31 +00:00
|
|
|
extern int hub_sendq_send(struct hub_sendq*, struct hub_user*);
|
2009-05-19 20:57:50 +00:00
|
|
|
|
2009-05-26 17:46:51 +00:00
|
|
|
/**
|
|
|
|
* @returns 1 if send queue is empty, 0 otherwise.
|
|
|
|
*/
|
|
|
|
extern int hub_sendq_is_empty(struct hub_sendq*);
|
2009-05-19 20:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-26 17:46:51 +00:00
|
|
|
* @returns the number of bytes remaining to be sent in the queue.
|
2009-05-19 20:57:50 +00:00
|
|
|
*/
|
2009-05-26 17:46:51 +00:00
|
|
|
extern size_t hub_sendq_get_bytes(struct hub_sendq*);
|
|
|
|
|
|
|
|
|
2009-05-19 20:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-26 17:46:51 +00:00
|
|
|
* Create a receive queue.
|
2009-05-19 20:57:50 +00:00
|
|
|
*/
|
2009-05-26 17:46:51 +00:00
|
|
|
extern struct hub_recvq* hub_recvq_create();
|
2009-05-19 20:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-26 17:46:51 +00:00
|
|
|
* Destroy a receive queue.
|
2009-05-19 20:57:50 +00:00
|
|
|
*/
|
2009-05-26 17:46:51 +00:00
|
|
|
extern void hub_recvq_destroy(struct hub_recvq*);
|
2009-05-19 20:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-26 17:46:51 +00:00
|
|
|
* Gets the buffer, copies it into buf and deallocates it.
|
|
|
|
* NOTE: bufsize *MUST* be larger than the buffer, otherwise it asserts.
|
|
|
|
* @return the number of bytes copied into buf.
|
2009-05-19 20:57:50 +00:00
|
|
|
*/
|
2009-05-26 17:46:51 +00:00
|
|
|
extern size_t hub_recvq_get(struct hub_recvq*, void* buf, size_t bufsize);
|
2009-05-19 20:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-26 17:46:51 +00:00
|
|
|
* Sets the buffer
|
2009-05-19 20:57:50 +00:00
|
|
|
*/
|
2009-05-26 17:46:51 +00:00
|
|
|
extern size_t hub_recvq_set(struct hub_recvq*, void* buf, size_t bufsize);
|
2009-05-19 20:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2009-05-26 17:46:51 +00:00
|
|
|
* @return 1 if size is zero, 0 otherwise.
|
2009-05-19 20:57:50 +00:00
|
|
|
*/
|
2009-05-26 17:46:51 +00:00
|
|
|
extern int hub_recvq_is_empty(struct hub_recvq* buf);
|
|
|
|
|
2009-05-19 20:57:50 +00:00
|
|
|
|
2009-05-24 19:07:16 +00:00
|
|
|
|
2009-05-26 17:46:51 +00:00
|
|
|
#endif /* HAVE_UHUB_HUB_IO_H */
|