Cleaning whitespaces/tabs and styling

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26803 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-08-04 20:03:23 +00:00
parent 20a5113818
commit 859039e124
3 changed files with 296 additions and 327 deletions

View File

@ -306,26 +306,22 @@ device_added(const usb_device* dev, void** cookie)
new_bt_dev->intr_in_ep = ep;
new_bt_dev->max_packet_size_intr_in = ep->descr->max_packet_size;
flowf("INT in\n");
} else
{
;
} else {
flowf("INT out\n");
}
break;
case USB_ENDPOINT_ATTR_BULK:
if (ep->descr->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN)
{
if (ep->descr->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN) {
new_bt_dev->bulk_in_ep = ep;
new_bt_dev->max_packet_size_bulk_in = ep->descr->max_packet_size;;
flowf("BULK int\n");
} else
{
} else {
new_bt_dev->bulk_out_ep = ep;
new_bt_dev->max_packet_size_bulk_out = ep->descr->max_packet_size;;
flowf("BULK out\n");
}
break;
break;
}
}
@ -442,41 +438,39 @@ device_open(const char *name, uint32 flags, void **cookie)
acquire_sem(bdev->lock);
// TX structures
for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) {
list_init(&bdev->nbuffersTx[i]);
bdev->nbuffersPendingTx[i] = 0;
list_init(&bdev->nbuffersTx[i]);
bdev->nbuffersPendingTx[i] = 0;
}
// RX structures
bdev->eventRx = NULL;
for (i = 0; i < BT_DRIVER_RXCOVERAGE; i++) {
bdev->nbufferRx[i] = NULL;
}
// dumping the USB frames
init_room(&bdev->eventRoom);
init_room(&bdev->aclRoom);
//init_room(new_bt_dev->scoRoom);
list_init(&bdev->snetBufferRecycleTrash);
list_init(&bdev->snetBufferRecycleTrash);
// Allocate set and register the HCI device
if (btDevices != NULL) {
struct net_device* ndev;
// TODO: Fill the transport descriptor
err = btDevices->init_device(bdev->name, &ndev);
if ( err == B_OK ) {
hdev = ndev->index;
bdev->ndev = ndev;
} else
hdev = bdev->num; /* XXX: Lets try to go on*/
}
else {
} else {
hdev = bdev->num; /* XXX: Lets try to go on*/
}
}
bdev->hdev = hdev;
bdev->hdev = hdev;
*cookie = bdev;
release_sem(bdev->lock);
@ -553,8 +547,7 @@ device_free (void *cookie)
/* GotoLowPower */
// interesting .....
}
else {
} else {
/* The last client has closed, and the device is no longer
connected, so remove it from the list. */
}
@ -604,12 +597,12 @@ device_control(void *cookie, uint32 msg, void *params, size_t size)
(*(size_t**)&params)++;
#endif
// TODO: Reuse from some TXcompleted queue
// TODO: Reuse from some TXcompleted queue
snbuf = snb_create(size);
snb_put(snbuf, params, size);
err = submit_tx_command(bdev, snbuf);
debugf("device launched %ld\n", err);
debugf("device launched %ld\n", err);
break;
case BT_UP:
@ -641,7 +634,7 @@ device_control(void *cookie, uint32 msg, void *params, size_t size)
flowf("device launched\n");
break;
case GET_STATICS:
case GET_STATS:
memcpy(params, &bdev->stat, sizeof(bt_hci_statistics));
err = B_OK;
break;
@ -668,7 +661,7 @@ static status_t
device_read(void *cookie, off_t pos, void *buf, size_t *count)
{
debugf("Reading... count = %ld\n", *count);
*count = 0;
return B_OK;
}
@ -810,10 +803,8 @@ publish_devices(void)
}
acquire_sem(dev_table_sem);
for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++)
{
if (bt_usb_devices[j] != NULL && bt_usb_devices[j]->connected)
{
for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) {
if (bt_usb_devices[j] != NULL && bt_usb_devices[j]->connected) {
str = strdup(bt_usb_devices[j]->name);
if (str) {
publish_names[i++] = str;
@ -842,16 +833,16 @@ publish_devices(void)
static device_hooks hooks = {
device_open,
device_close,
device_free,
device_control,
device_read,
device_open,
device_close,
device_free,
device_control,
device_read,
device_write,
NULL,
NULL,
NULL,
NULL
NULL
};

View File

@ -39,100 +39,98 @@ void event_complete(void* cookie, status_t status, void* data, size_t actual_len
static status_t
assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
{
net_buffer* nbuf = NULL;
snet_buffer* snbuf = NULL;
size_t currentPacketLen = 0;
size_t expectedPacketLen = 0;
{
net_buffer* nbuf = NULL;
snet_buffer* snbuf = NULL;
size_t currentPacketLen = 0;
size_t expectedPacketLen = 0;
bdev->stat.bytesRX += count;
bdev->stat.bytesRX += count;
if (type == BT_EVENT)
snbuf = bdev->eventRx;
else
nbuf = bdev->nbufferRx[type];
nbuf = bdev->nbufferRx[type];
while (count) {
while (count) {
debugf("count %d nb=%p sb=%p type=%d\n",count, nbuf, snbuf, type);
if ( (type != BT_EVENT && nbuf == NULL) ||
(type == BT_EVENT && (snbuf == NULL || snb_completed(snbuf))) ) {
if ( (type != BT_EVENT && nbuf == NULL) ||
(type == BT_EVENT && (snbuf == NULL || snb_completed(snbuf))) ) {
/* new buffer incoming */
switch (type) {
case BT_EVENT:
if (count >= HCI_EVENT_HDR_SIZE) {
struct hci_event_header* headerPkt = data;
expectedPacketLen = HCI_EVENT_HDR_SIZE + headerPkt->elen;
snbuf = bdev->eventRx = snb_fetch(&bdev->snetBufferRecycleTrash, expectedPacketLen);
} else {
flowf("EVENT frame corrupted\n");
return -EILSEQ;
}
break;
case BT_ACL:
if (count >= HCI_ACL_HDR_SIZE) {
int16 index;
struct hci_acl_header* headerPkt = data;
/* new buffer incoming */
switch (type) {
case BT_EVENT:
if (count >= HCI_EVENT_HDR_SIZE) {
struct hci_event_header* headerPkt = data;
expectedPacketLen = HCI_EVENT_HDR_SIZE + headerPkt->elen;
snbuf = bdev->eventRx = snb_fetch(&bdev->snetBufferRecycleTrash, expectedPacketLen);
} else {
flowf("EVENT frame corrupted\n");
return -EILSEQ;
}
break;
case BT_ACL:
if (count >= HCI_ACL_HDR_SIZE) {
int16 index;
struct hci_acl_header* headerPkt = data;
expectedPacketLen = HCI_ACL_HDR_SIZE + B_LENDIAN_TO_HOST_INT16(headerPkt->alen);
/* Create the buffer */
bdev->nbufferRx[type] = nbuf = nb->create(expectedPacketLen);
// TODO: this allocation can fail!!
nbuf->protocol = type;
debugf("new ACL frame %p\n", nbuf);
expectedPacketLen = HCI_ACL_HDR_SIZE + B_LENDIAN_TO_HOST_INT16(headerPkt->alen);
/* Create the buffer */
bdev->nbufferRx[type] = nbuf = nb->create(expectedPacketLen);
// TODO: this allocation can fail!!
nbuf->protocol = type;
debugf("new ACL frame %p\n", nbuf);
debugf("### Incoming ACL: len = %d\n", count);
for (index = 0 ; index < count; index++ ) {
dprintf("%x:",((uint8*)data)[index]);
}
flowf("### \n");
} else {
flowf("ACL frame corrupted\n");
return -EILSEQ;
}
break;
case BT_SCO:
break;
default:
panic("unkown packet type in assembly");
break;
}
currentPacketLen = expectedPacketLen;
} else {
flowf("ACL frame corrupted\n");
return -EILSEQ;
}
break;
case BT_SCO:
}
else {
/* Continuation */
if (type != BT_EVENT)
currentPacketLen = get_expected_size(nbuf) - nbuf->size;
else
currentPacketLen = snb_remaining_to_put(snbuf);
}
break;
default:
panic("unkown packet type in assembly");
break;
}
currentPacketLen = min(currentPacketLen, count);
currentPacketLen = expectedPacketLen;
if (type == BT_EVENT)
snb_put(snbuf, data, currentPacketLen);
} else {
/* Continuation */
if (type != BT_EVENT)
currentPacketLen = get_expected_size(nbuf) - nbuf->size;
else
currentPacketLen = snb_remaining_to_put(snbuf);
}
currentPacketLen = min(currentPacketLen, count);
if (type == BT_EVENT)
snb_put(snbuf, data, currentPacketLen);
else
nb->append(nbuf, data, currentPacketLen);
nb->append(nbuf, data, currentPacketLen);
/* Complete frame? */
if (type == BT_EVENT && snb_completed(snbuf)) {
if (type == BT_EVENT && snb_completed(snbuf)) {
post_packet_up(bdev, type, snbuf);
snbuf = bdev->eventRx = NULL;
}
}
if (type != BT_EVENT && (get_expected_size(nbuf) - nbuf->size) == 0 ) {
post_packet_up(bdev, type, nbuf);
@ -141,13 +139,13 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
if (type == BT_ACL)
debugf("ACL Packet not filled size=%ld expected=%ld\n", nbuf->size, get_expected_size(nbuf));
}*/
/* in case in the pipe there is info about the next buffer ... */
/* in case in the pipe there is info about the next buffer ... */
count -= currentPacketLen;
data += currentPacketLen;
}
return B_OK;
}
return B_OK;
}
@ -163,38 +161,36 @@ event_complete(void* cookie, uint32 status, void* data, uint32 actual_len)
event_complete(void* cookie, status_t status, void* data, size_t actual_len)
#endif
{
bt_usb_dev* bdev = cookie;
status_t err;
/* TODO: or not running anymore */
bt_usb_dev* bdev = cookie;
status_t err;
/* TODO: or not running anymore */
if (status == B_CANCELED)
return;
if (status != B_OK || actual_len == 0)
goto resubmit;
if (status != B_OK || actual_len == 0)
goto resubmit;
if ( assembly_rx(cookie, BT_EVENT, data, actual_len) == B_OK ) {
bdev->stat.successfulTX++;
} else {
bdev->stat.errorRX++;
}
if ( assembly_rx(cookie, BT_EVENT, data, actual_len) == B_OK ) {
bdev->stat.successfulTX++;
} else {
bdev->stat.errorRX++;
}
resubmit:
err = usb->queue_interrupt(bdev->intr_in_ep->handle,
data, bdev->max_packet_size_intr_in ,
event_complete, bdev);
err = usb->queue_interrupt(bdev->intr_in_ep->handle,
data, bdev->max_packet_size_intr_in ,
event_complete, bdev);
if (err != B_OK) {
reuse_room(&bdev->eventRoom, data);
bdev->stat.rejectedRX++;
debugf("RX event resubmittion failed %s\n",strerror(err));
} else {
bdev->stat.acceptedRX++;
}
if (err != B_OK ) {
reuse_room(&bdev->eventRoom, data);
bdev->stat.rejectedRX++;
debugf("RX event resubmittion failed %s\n",strerror(err));
}
else {
bdev->stat.acceptedRX++;
}
}
@ -205,67 +201,64 @@ acl_rx_complete(void* cookie, uint32 status, void* data, uint32 actual_len)
acl_rx_complete(void* cookie, status_t status, void* data, size_t actual_len)
#endif
{
bt_usb_dev* bdev = cookie;
status_t err;
/* TODO: or not running anymore? */
bt_usb_dev* bdev = cookie;
status_t err;
/* TODO: or not running anymore? */
if (status == B_CANCELED)
return;
if (status != B_OK || actual_len == 0)
goto resubmit;
if (status != B_OK || actual_len == 0)
goto resubmit;
if (assembly_rx(cookie, BT_ACL, data, actual_len) == B_OK) {
bdev->stat.successfulRX++;
} else {
bdev->stat.errorRX++;
}
if ( assembly_rx(cookie, BT_ACL, data, actual_len) == B_OK ) {
bdev->stat.successfulRX++;
} else {
bdev->stat.errorRX++;
}
resubmit:
err = usb->queue_bulk(bdev->bulk_in_ep->handle, data,
max(HCI_MAX_FRAME_SIZE,bdev->max_packet_size_bulk_in),
acl_rx_complete, (void*) bdev);
max(HCI_MAX_FRAME_SIZE,bdev->max_packet_size_bulk_in),
acl_rx_complete, (void*) bdev);
if (err != B_OK ) {
reuse_room(&bdev->aclRoom, data);
bdev->stat.rejectedRX++;
debugf("RX acl resubmittion failed %s\n", strerror(err));
}
else {
bdev->stat.acceptedRX++;
}
if (err != B_OK) {
reuse_room(&bdev->aclRoom, data);
bdev->stat.rejectedRX++;
debugf("RX acl resubmittion failed %s\n", strerror(err));
} else {
bdev->stat.acceptedRX++;
}
}
#if 0
#pragma mark --- RX ---
#endif
status_t
submit_rx_event(bt_usb_dev* bdev)
{
status_t status;
size_t size = bdev->max_packet_size_intr_in;
void* buf = alloc_room(&bdev->eventRoom, size);
if (buf == NULL)
return ENOMEM;
{
status_t status;
size_t size = bdev->max_packet_size_intr_in;
void* buf = alloc_room(&bdev->eventRoom, size);
status = usb->queue_interrupt(bdev->intr_in_ep->handle,
buf, size ,
event_complete, (void*) bdev);
if (status != B_OK ) {
reuse_room(&bdev->eventRoom, buf); // reuse allocated one
bdev->stat.rejectedRX++;
}
else {
bdev->stat.acceptedRX++;
debugf("Accepted RX Event %d\n", bdev->stat.acceptedRX);
}
return status;
if (buf == NULL)
return ENOMEM;
status = usb->queue_interrupt(bdev->intr_in_ep->handle,
buf, size ,
event_complete, (void*) bdev);
if (status != B_OK) {
reuse_room(&bdev->eventRoom, buf); // reuse allocated one
bdev->stat.rejectedRX++;
} else {
bdev->stat.acceptedRX++;
debugf("Accepted RX Event %d\n", bdev->stat.acceptedRX);
}
return status;
}
@ -273,34 +266,32 @@ status_t
submit_rx_acl(bt_usb_dev* bdev)
{
status_t status;
size_t size = max(HCI_MAX_FRAME_SIZE,bdev->max_packet_size_bulk_in);
void* buf = alloc_room(&bdev->aclRoom, size);
status_t status;
size_t size = max(HCI_MAX_FRAME_SIZE,bdev->max_packet_size_bulk_in);
void* buf = alloc_room(&bdev->aclRoom, size);
if (buf == NULL)
return ENOMEM;
status = usb->queue_bulk(bdev->bulk_in_ep->handle, buf, size ,
acl_rx_complete, bdev);
if (buf == NULL)
return ENOMEM;
if (status != B_OK ) {
reuse_room(&bdev->aclRoom, buf); // reuse allocated
bdev->stat.rejectedRX++;
}
else {
bdev->stat.acceptedRX++;
}
return status;
status = usb->queue_bulk(bdev->bulk_in_ep->handle, buf, size ,
acl_rx_complete, bdev);
if (status != B_OK) {
reuse_room(&bdev->aclRoom, buf); // reuse allocated
bdev->stat.rejectedRX++;
} else {
bdev->stat.acceptedRX++;
}
return status;
}
status_t
submit_rx_sco(bt_usb_dev* bdev)
{
/* not yet implemented */
return B_ERROR;
/* not yet implemented */
return B_ERROR;
}
@ -316,28 +307,26 @@ command_complete(void* cookie, uint32 status, void* data, uint32 actual_len)
command_complete(void* cookie, status_t status, void* data, size_t actual_len)
#endif
{
snet_buffer* snbuf = (snet_buffer*) cookie;
bt_usb_dev* bdev = snb_cookie(snbuf);
snet_buffer* snbuf = (snet_buffer*) cookie;
bt_usb_dev* bdev = snb_cookie(snbuf);
debugf("%ld %02x:%02x:%02x:\n", actual_len, ((uint8*)data)[0],((uint8*)data)[1],((uint8*)data)[2]);
debugf("%ld %02x:%02x:%02x:\n", actual_len, ((uint8*)data)[0],((uint8*)data)[1],((uint8*)data)[2]);
if (status != B_OK) {
bdev->stat.successfulTX++;
bdev->stat.bytesTX += actual_len;
}
else {
bdev->stat.errorTX++;
/* the packet has been lost */
/* too late to requeue it? */
}
if (status != B_OK) {
bdev->stat.successfulTX++;
bdev->stat.bytesTX += actual_len;
} else {
bdev->stat.errorTX++;
/* the packet has been lost */
/* too late to requeue it? */
}
snb_park(&bdev->snetBufferRecycleTrash, snbuf);
snb_park(&bdev->snetBufferRecycleTrash, snbuf);
#ifdef BT_RESCHEDULING_AFTER_COMPLETITIONS
// TODO: check just the empty queues?
schedTxProcessing(bdev);
#endif
// TODO: check just the empty queues?
schedTxProcessing(bdev);
#endif
}
@ -347,92 +336,85 @@ acl_tx_complete(void* cookie, uint32 status, void* data, uint32 actual_len)
#else
acl_tx_complete(void* cookie, status_t status, void* data, size_t actual_len)
#endif
{
net_buffer* nbuf = (net_buffer*) cookie;
bt_usb_dev* bdev = GET_DEVICE(nbuf);
net_buffer* nbuf = (net_buffer*) cookie;
bt_usb_dev* bdev = GET_DEVICE(nbuf);
if (status != B_OK) {
if (status != B_OK) {
bdev->stat.successfulTX++;
bdev->stat.bytesTX += actual_len;
}
else {
bdev->stat.errorTX++;
/* the packet has been lost */
/* too late to requeue it? */
}
nb_destroy(nbuf);
bdev->stat.successfulTX++;
bdev->stat.bytesTX += actual_len;
} else {
bdev->stat.errorTX++;
/* the packet has been lost */
/* too late to requeue it? */
}
nb_destroy(nbuf);
#ifdef BT_RESCHEDULING_AFTER_COMPLETITIONS
schedTxProcessing(bdev);
#endif
schedTxProcessing(bdev);
#endif
}
#if 0
#pragma mark --- TX ---
#endif
status_t
submit_tx_command(bt_usb_dev* bdev, snet_buffer* snbuf)
{
status_t err;
uint8 bRequestType = bdev->ctrl_req;
{
status_t err;
uint8 bRequestType = bdev->ctrl_req;
uint8 bRequest = 0;
uint16 wIndex = 0;
uint16 value = 0;
uint16 wLength = B_HOST_TO_LENDIAN_INT16(snb_size(snbuf));
if (!GET_BIT(bdev->state, RUNNING) ) {
if (!GET_BIT(bdev->state, RUNNING)) {
return B_DEV_NOT_READY;
}
/* set cookie */
snb_set_cookie(snbuf, bdev);
/* set cookie */
snb_set_cookie(snbuf, bdev);
err = usb->queue_request(bdev->dev, bRequestType, bRequest,
value, wIndex, wLength,
snb_get(snbuf), wLength //???
,command_complete, (void*) snbuf);
value, wIndex, wLength,
snb_get(snbuf), wLength //???
,command_complete, (void*) snbuf);
if (err != B_OK ) {
bdev->stat.rejectedTX++;
}
else {
bdev->stat.acceptedTX++;
}
bdev->stat.rejectedTX++;
} else {
bdev->stat.acceptedTX++;
}
return err;
return err;
}
status_t
submit_tx_acl(bt_usb_dev* bdev, net_buffer* nbuf)
{
status_t err;
/* set cookie */
SET_DEVICE(nbuf,bdev->hdev);
status_t err;
/* set cookie */
SET_DEVICE(nbuf,bdev->hdev);
if (!GET_BIT(bdev->state, RUNNING) ) {
return B_DEV_NOT_READY;
}
err = usb->queue_bulk(bdev->bulk_out_ep->handle,
nb_get_whole_buffer(nbuf), nbuf->size,
acl_tx_complete, (void*) nbuf);
if (err != B_OK ) {
bdev->stat.rejectedTX++;
}
else {
bdev->stat.acceptedTX++;
}
err = usb->queue_bulk(bdev->bulk_out_ep->handle,
nb_get_whole_buffer(nbuf), nbuf->size,
acl_tx_complete, (void*) nbuf);
return err;
if (err != B_OK ) {
bdev->stat.rejectedTX++;
} else {
bdev->stat.acceptedTX++;
}
return err;
}
@ -440,11 +422,10 @@ status_t
submit_tx_sco(bt_usb_dev* bdev)
{
if (!GET_BIT(bdev->state, RUNNING) ) {
if (!GET_BIT(bdev->state, RUNNING)) {
return B_DEV_NOT_READY;
}
/* not yet implemented */
return B_ERROR;
/* not yet implemented */
return B_ERROR;
}

View File

@ -13,63 +13,62 @@
struct snet_buffer {
struct list_link link;
uint8* buffer;
uint8* buffer;
uint16 allocatedSize;
uint16 expectedSize;
uint16 puttingSize;
uint16 pullingSize;
void* cookie;
uint16 expectedSize;
uint16 puttingSize;
uint16 pullingSize;
void* cookie;
};
snet_buffer*
snb_create(uint16 size)
{
/* TODO: pointer checking */
/* TODO: pointer checking */
#ifdef SNB_BUFFER_ATTACHED
/* Allocating these 2 buffers together might prevent memory fragmentation? */
snet_buffer* snb = (snet_buffer*) malloc(sizeof(snet_buffer) + size);
snb->buffer = ((uint8*)snb) + sizeof(snet_buffer);
/* Allocating these 2 buffers together might prevent memory fragmentation? */
snet_buffer* snb = (snet_buffer*) malloc(sizeof(snet_buffer) + size);
snb->buffer = ((uint8*)snb) + sizeof(snet_buffer);
#else
snet_buffer* snb = malloc(sizeof (snet_buffer));
snb->buffer = malloc(size);
snet_buffer* snb = malloc(sizeof (snet_buffer));
snb->buffer = malloc(size);
#endif
snb->pullingSize = snb->puttingSize = 0;
snb->expectedSize = snb->allocatedSize = size;
return snb;
snb->pullingSize = snb->puttingSize = 0;
snb->expectedSize = snb->allocatedSize = size;
return snb;
}
void
snb_put(snet_buffer* snb, void* data, uint16 size)
{
/* TODO: check overflow */
memcpy( &snb->buffer[snb->puttingSize], data, size);
snb->puttingSize+=size;
/* TODO: check overflow */
memcpy( &snb->buffer[snb->puttingSize], data, size);
snb->puttingSize+=size;
}
void*
snb_pull(snet_buffer* snb, uint16 size)
{
/* TODO: check overflow */
snb->pullingSize+=size;
return &snb->buffer[snb->pullingSize-size];
/* TODO: check overflow */
snb->pullingSize+=size;
return &snb->buffer[snb->pullingSize-size];
}
inline void
snb_reset(snet_buffer* snb)
{
snb->puttingSize = snb->pullingSize = 0;
snb->puttingSize = snb->pullingSize = 0;
}
@ -80,10 +79,10 @@ snb_free(snet_buffer* snb)
return;
#ifdef SNB_BUFFER_ATTACHED
free(snb);
free(snb);
#else
free(snb->buffer);
free(snb);
free(snb->buffer);
free(snb);
#endif
}
@ -92,90 +91,89 @@ snb_free(snet_buffer* snb)
inline void*
snb_get(snet_buffer* snb)
{
/* TODO: pointer checking */
return snb->buffer;
/* TODO: pointer checking */
return snb->buffer;
}
inline uint16
snb_size(snet_buffer* snb)
{
/* TODO: pointer checking */
return snb->expectedSize;
/* TODO: pointer checking */
return snb->expectedSize;
}
inline void*
snb_cookie(snet_buffer* snb)
{
/* TODO: pointer checking */
return snb->cookie;
/* TODO: pointer checking */
return snb->cookie;
}
inline void
snb_set_cookie(snet_buffer* snb, void* cookie)
{
/* TODO: pointer checking */
snb->cookie = cookie;
/* TODO: pointer checking */
snb->cookie = cookie;
}
/* Return true if we canot "put" more data in the buffer */
inline bool snb_completed(snet_buffer* snb)
{
return (snb->expectedSize == snb->puttingSize);
return (snb->expectedSize == snb->puttingSize);
}
/* Return true if we cannot pull more more data from the buffer */
inline bool snb_finished(snet_buffer* snb)
{
return (snb->expectedSize == snb->pullingSize);
return (snb->expectedSize == snb->pullingSize);
}
inline uint16 snb_remaining_to_put(snet_buffer* snb)
{
return (snb->expectedSize - snb->puttingSize);
return (snb->expectedSize - snb->puttingSize);
}
inline uint16 snb_remaining_to_pull(snet_buffer* snb)
{
return (snb->expectedSize - snb->pullingSize);
return (snb->expectedSize - snb->pullingSize);
}
/* ISSUE1: Number of packets in the worst case(we always need a bigger
buffer than before) increases, never decreases:
SOL1: Delete the smallest when the queue is bigger than X elements
SOL2: ?
ISSUE2: If the queue is not gonna be used for long time. Memory c
ould be freed
SOL1: Provide purge func.
SOL2: ?
*/
static snet_buffer*
snb_attempt_reuse(snet_buffer* snb, uint16 size)
{
if ( snb == NULL ||
((int16)snb->allocatedSize - (int16)size) < 0 ) {
if ( snb == NULL ||
((int16)snb->allocatedSize - (int16)size) < 0 ) {
/* Impossible or not worth, Creating a new one */
snb_free(snb);
return snb_create(size);
/* Impossible or not worth, Creating a new one */
snb_free(snb);
return snb_create(size);
}
else {
snb_reset(snb);
snb->expectedSize = size;
return snb;
}
} else {
snb_reset(snb);
snb->expectedSize = size;
return snb;
}
}
@ -195,7 +193,6 @@ snb_park(struct list* l, snet_buffer* snb)
snet_buffer*
snb_fetch(struct list* l, uint16 size)
{
snet_buffer* item = NULL;
snet_buffer* previous = NULL;