本文整理汇总了C++中rr_dev::want_writable方法的典型用法代码示例。如果您正苦于以下问题:C++ rr_dev::want_writable方法的具体用法?C++ rr_dev::want_writable怎么用?C++ rr_dev::want_writable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rr_dev
的用法示例。
在下文中一共展示了rr_dev::want_writable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rr_enqueue_internal
void rr_enqueue_internal(rr_dev device, rr_prio priority, void *cbdata, const char *block, size_t nbytes, long long line) {
blocknode *node = malloc(sizeof(blocknode));
node->next = NULL;
node->cbdata = cbdata;
node->block = malloc(nbytes);
memcpy(node->block, block, nbytes);
node->blocksize = nbytes;
node->line = line;
if(!device->sendhead[priority]) {
device->sendhead[priority] = node;
device->sendtail[priority] = node;
device->want_writable(device, device->ww_data, 1);
} else {
device->sendtail[priority]->next = node;
device->sendtail[priority] = node;
}
}
示例2: rr_handle_writable
int rr_handle_writable(rr_dev device) {
ssize_t result;
if(device->sendbuf_fill == 0) {
/* Last block is gone; prepare to send a new block */
int prio;
blocknode *node = NULL;
for(prio = RR_PRIO_COUNT - 1; prio >= 0; --prio) {
node = device->sendhead[prio];
if(node) {
/* We have a block to send! Get it ready. */
device->bytes_sent = 0;
result = fmtblock(device, node);
if(result < 0) {
/* FIXME: This will confuse code expecting errno to be set */
return result;
}
device->sendbuf_fill = result;
device->sending_prio = prio;
break;
}
}
if(!node) {
/* No data to write */
device->want_writable(device, device->ww_data, 0);
return 0;
}
}
/* Perform write */
do {
result = write(device->fd, device->sendbuf + device->bytes_sent, device->sendbuf_fill - device->bytes_sent);
} while(result < 0 && errno == EINTR);
if(result < 0) {
return result;
}
device->bytes_sent += result;
if(device->bytes_sent == device->sendbuf_fill) {
/* We've sent the complete block. */
blocknode *node = device->sendhead[device->sending_prio];
if(device->onsend) {
device->onsend(device, device->onsend_data, node->cbdata, device->sendbuf, device->sendbuf_fill);
}
device->sendhead[device->sending_prio] = node->next;
node->line = device->lineno;
++(device->lineno);
/* Update sent cache */
if(device->sentcache[device->sentcachesize - 1]) {
blocknode_free(device->sentcache[device->sentcachesize - 1]);
}
ssize_t i;
for(i = device->sentcachesize - 1; i > 0 ; --i) {
device->sentcache[i] = device->sentcache[i-1];
}
device->sentcache[0] = node;
/* Indicate that we're ready for the next. */
device->sendbuf_fill = 0;
}
return result;
}