本文整理汇总了C++中do_read函数的典型用法代码示例。如果您正苦于以下问题:C++ do_read函数的具体用法?C++ do_read怎么用?C++ do_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: start
void start()
{
g_client_count++;
//set_socket_recv_bufsize(MAX_PACKET_SIZE);
do_read();
}
开发者ID:shines77,项目名称:netlib_test,代码行数:6,代码来源:asio_connection.hpp
示例2: read_30
static int read_30 ( struct net_device *dev)
{
lt_command c;
c.getflags.command = LT_GETFLAGS;
return do_read(dev, &c, sizeof(c.getflags),&c,0);
}
开发者ID:robacklin,项目名称:ts7800,代码行数:6,代码来源:ltpc.c
示例3: do_command
static int do_command(cmd_request_t cmd)
{
char *buf;
struct boothc_header *h, reply;
int buflen;
uint32_t force = 0;
int fd, rv;
buflen = sizeof(struct boothc_header) +
sizeof(cl.site) + sizeof(cl.ticket);
buf = malloc(buflen);
if (!buf) {
rv = -ENOMEM;
goto out;
}
h = (struct boothc_header *)buf;
if (cl.force)
force = BOOTHC_OPT_FORCE;
init_header(h, cmd, force, 0,
sizeof(cl.site) + sizeof(cl.ticket));
strcpy(buf + sizeof(struct boothc_header), cl.site);
strcpy(buf + sizeof(struct boothc_header) + sizeof(cl.site), cl.ticket);
fd = do_connect(BOOTHC_SOCK_PATH);
if (fd < 0) {
rv = fd;
goto out_free;
}
rv = do_write(fd, buf, buflen);
if (rv < 0)
goto out_close;
rv = do_read(fd, &reply, sizeof(struct boothc_header));
if (rv < 0)
goto out_close;
if (reply.result == BOOTHC_RLT_INVALID_ARG) {
log_info("invalid argument!");
rv = -1;
goto out_close;
}
if (reply.result == BOOTHC_RLT_REMOTE_OP) {
struct booth_node to;
int s;
memset(&to, 0, sizeof(struct booth_node));
to.family = BOOTH_PROTO_FAMILY;
strcpy(to.addr, cl.site);
s = booth_transport[TCP].open(&to);
if (s < 0)
goto out_close;
rv = booth_transport[TCP].send(s, buf, buflen);
if (rv < 0) {
booth_transport[TCP].close(s);
goto out_close;
}
rv = booth_transport[TCP].recv(s, &reply,
sizeof(struct boothc_header));
if (rv < 0) {
booth_transport[TCP].close(s);
goto out_close;
}
booth_transport[TCP].close(s);
}
if (reply.result == BOOTHC_RLT_ASYNC) {
if (cmd == BOOTHC_CMD_GRANT)
log_info("grant command sent, result will be returned "
"asynchronously, you can get the result from "
"the log files");
else if (cmd == BOOTHC_CMD_REVOKE)
log_info("revoke command sent, result will be returned "
"asynchronously, you can get the result from "
"the log files after the ticket expiry time.");
else
log_error("internal error reading reply result!");
rv = 0;
} else if (reply.result == BOOTHC_RLT_SYNC_SUCC) {
if (cmd == BOOTHC_CMD_GRANT)
log_info("grant succeeded!");
else if (cmd == BOOTHC_CMD_REVOKE)
log_info("revoke succeeded!");
rv = 0;
} else if (reply.result == BOOTHC_RLT_SYNC_FAIL) {
if (cmd == BOOTHC_CMD_GRANT)
log_info("grant failed!");
else if (cmd == BOOTHC_CMD_REVOKE)
log_info("revoke failed!");
rv = 0;
} else {
log_error("internal error!");
rv = -1;
}
out_close:
close(fd);
//.........这里部分代码省略.........
开发者ID:aspiers,项目名称:booth,代码行数:101,代码来源:main.c
示例4: self
void connection::do_read()
{
auto self(shared_from_this());
socket_.async_read_some(boost::asio::buffer(buffer_),
[this, self](boost::system::error_code ec, std::size_t bytes_transferred)
{
if (!ec)
{
if (ws_connected)
{
ws_frame frame;
frame.fin = 0x80 & buffer_[0];
frame.masking = 0x80 & buffer_[1];
frame.payload_len = (unsigned int)(buffer_[1] & 0x7F);
int masking_key_offset = 0;
// If 126, the following 2 bytes interpreted as a 16 - bit unsigned integer are the payload length.
if (frame.payload_len == 126)
{
masking_key_offset = 2;
unsigned short s = ((buffer_[2] << 8) | buffer_[3]);
frame.payload_len = s;
}
// If 127, the following 8 bytes interpreted as a 64 - bit unsigned integer(the most significant bit MUST be 0) are the payload length.
else if (frame.payload_len == 127)
{
unsigned long long int s =
(
(buffer_[2] << 64) | (buffer_[3] << 56) | (buffer_[4] << 48) |
(buffer_[5] << 40) | (buffer_[6] << 32) | (buffer_[7] << 24) |
(buffer_[8] << 12) | (buffer_[9] << 4) | buffer_[10]
);
frame.payload_len = s;
masking_key_offset = 8;
}
if (frame.masking)
{
frame.masking_key[0] = (buffer_[2] + masking_key_offset);
frame.masking_key[1] = (buffer_[3] + masking_key_offset);
frame.masking_key[2] = (buffer_[4] + masking_key_offset);
frame.masking_key[3] = (buffer_[5] + masking_key_offset);
}
else
{
frame.masking_key[0] = 0;
frame.masking_key[1] = 0;
frame.masking_key[2] = 0;
frame.masking_key[3] = 0;
}
frame.payload = std::vector<unsigned char>();
for (int i = 0; i < frame.payload_len; ++i)
{
unsigned char original = buffer_[6 + masking_key_offset + i];
frame.payload.push_back(original ^ frame.masking_key[i % 4]);
}
printf("masking: %s\n payload: %d bytes\n", frame.masking ? "True" : "False", frame.payload_len);
printf("Data: %s\n", frame.payload.data());
//do_write("Data: %s\n", 5);
do_read();
return;
}
request_parser::result_type result;
std::tie(result, std::ignore) = request_parser_.parse(
request_, buffer_.data(), buffer_.data() + bytes_transferred);
if (result == request_parser::good)
{
request_handler_.handle_request(request_, reply_);
if (reply_.status == reply::switching_protocols)
{
ws_connected = true;
}
do_write_http();
}
else if (result == request_parser::bad)
{
reply_ = reply::stock_reply(reply::bad_request);
do_write_http();
}
else
{
do_read();
}
}
else if (ec != boost::asio::error::operation_aborted)
{
connection_manager_.stop(shared_from_this());
}
});
}
开发者ID:Rarau,项目名称:asio_websocket_server,代码行数:98,代码来源:connection.cpp
示例5: read_op
gf8 read_op(char op, char * s, int * index) {
gf8 left = do_read(s,index);
gf8 right = do_read(s,index);
return do_op(op, left, right);
}
开发者ID:AarhusCrypto,项目名称:MiniAES,代码行数:5,代码来源:gf8calc.c
示例6: tcpip_task
void tcpip_task( void *dummy)
{
/* wait for an IO signal, find out what is happening and
* call the right routine to handle the situation.
*/
fd_set rfds, *pfds;
#ifndef __linux__
fd_set efds;
#endif
int conn_id, ret, count;
#ifndef WIN32
int data;
#endif
if(dummy){}
while(1)
{
while(!DIM_IO_valid)
dim_usleep(1000);
list_to_fds( &rfds );
MY_FD_ZERO(&efds);
#ifdef WIN32
pfds = &efds;
#else
pfds = &rfds;
#endif
MY_FD_SET( DIM_IO_path[0], pfds );
#ifdef __linux__
ret = poll(Pollfds, Pollfd_size, -1);
#else
ret = select(FD_SETSIZE, &rfds, NULL, &efds, NULL);
#endif
if(ret <= 0)
{
printf("poll returned %d, errno %d\n", ret, errno);
}
if(ret > 0)
{
if(MY_FD_ISSET(DIM_IO_path[0], pfds) )
{
#ifndef WIN32
read(DIM_IO_path[0], &data, 4);
DIM_IO_Done = 0;
#endif
MY_FD_CLR( (unsigned)DIM_IO_path[0], pfds );
}
/*
{
DISABLE_AST
*/
conn_id = 0;
while( (ret = fds_get_entry( &rfds, &conn_id )) > 0 )
{
if( Net_conns[conn_id].reading )
{
count = 0;
do
{
DISABLE_AST
if(Net_conns[conn_id].channel)
{
do_read( conn_id );
count = get_bytes_to_read(conn_id);
}
else
{
count = 0;
}
ENABLE_AST
}while(count > 0 );
}
else
{
DISABLE_AST
do_accept( conn_id );
ENABLE_AST
}
MY_FD_CLR( (unsigned)Net_conns[conn_id].channel, &rfds );
}
/*
ENABLE_AST
}
*/
#ifndef WIN32
return;
#endif
}
开发者ID:AHCALMonitoring,项目名称:dim,代码行数:87,代码来源:tcpip.c
示例7: rshd_loop
static void
rshd_loop (int from0, int to0,
int to1, int from1,
int to2, int from2,
int have_errsock)
{
fd_set real_readset;
int max_fd;
int count = 2;
char *buf;
if(from0 >= FD_SETSIZE || from1 >= FD_SETSIZE || from2 >= FD_SETSIZE)
errx (1, "fd too large");
#ifdef KRB5
if(auth_method == AUTH_KRB5 && protocol_version == 2)
init_ivecs(0, have_errsock);
#endif
FD_ZERO(&real_readset);
FD_SET(from0, &real_readset);
FD_SET(from1, &real_readset);
FD_SET(from2, &real_readset);
max_fd = max(from0, max(from1, from2)) + 1;
buf = malloc(max(RSHD_BUFSIZ, RSH_BUFSIZ));
if (buf == NULL)
syslog_and_die("out of memory");
for (;;) {
int ret;
fd_set readset = real_readset;
ret = select (max_fd, &readset, NULL, NULL, NULL);
if (ret < 0) {
if (errno == EINTR)
continue;
else
syslog_and_die ("select: %s", strerror(errno));
}
if (FD_ISSET(from0, &readset)) {
ret = do_read (from0, buf, RSHD_BUFSIZ, ivec_in[0]);
if (ret < 0)
syslog_and_die ("read: %s", strerror(errno));
else if (ret == 0) {
close (from0);
close (to0);
FD_CLR(from0, &real_readset);
} else
net_write (to0, buf, ret);
}
if (FD_ISSET(from1, &readset)) {
ret = read (from1, buf, RSH_BUFSIZ);
if (ret < 0)
syslog_and_die ("read: %s", strerror(errno));
else if (ret == 0) {
close (from1);
close (to1);
FD_CLR(from1, &real_readset);
if (--count == 0)
exit (0);
} else
do_write (to1, buf, ret, ivec_out[0]);
}
if (FD_ISSET(from2, &readset)) {
ret = read (from2, buf, RSH_BUFSIZ);
if (ret < 0)
syslog_and_die ("read: %s", strerror(errno));
else if (ret == 0) {
close (from2);
close (to2);
FD_CLR(from2, &real_readset);
if (--count == 0)
exit (0);
} else
do_write (to2, buf, ret, ivec_out[1]);
}
}
}
开发者ID:2asoft,项目名称:freebsd,代码行数:79,代码来源:rshd.c
示例8: run
//.........这里部分代码省略.........
{
if (errno == EADDRINUSE)
{
dbg_tty_printf(g,1,"there is already a epmd running at port %d",
g->port);
epmd_cleanup_exit(g,0);
}
else
{
dbg_perror(g,"failed to bind socket");
epmd_cleanup_exit(g,1);
}
}
if(listen(listensock[i], SOMAXCONN) < 0) {
dbg_perror(g,"failed to listen on socket");
epmd_cleanup_exit(g,1);
}
select_fd_set(g, listensock[i]);
}
if (bound == 0) {
dbg_perror(g,"unable to bind any address");
epmd_cleanup_exit(g,1);
}
num_sockets = bound;
#ifdef HAVE_SYSTEMD_DAEMON
}
sd_notifyf(0, "READY=1\n"
"STATUS=Processing port mapping requests...\n"
"MAINPID=%lu", (unsigned long) getpid());
#endif /* HAVE_SYSTEMD_DAEMON */
dbg_tty_printf(g,2,"entering the main select() loop");
select_again:
while(1)
{
fd_set read_mask = g->orig_read_mask;
struct timeval timeout;
int ret;
/* If we are idle we time out now and then to enable the code
below to close connections that are old and probably
hanging. Make sure that select will return often enough. */
timeout.tv_sec = (g->packet_timeout < IDLE_TIMEOUT) ? 1 : IDLE_TIMEOUT;
timeout.tv_usec = 0;
if ((ret = select(g->select_fd_top,
&read_mask, (fd_set *)0,(fd_set *)0,&timeout)) < 0) {
dbg_perror(g,"error in select ");
switch (errno) {
case EAGAIN:
case EINTR:
break;
default:
epmd_cleanup_exit(g,1);
}
}
else {
time_t now;
if (ret == 0) {
FD_ZERO(&read_mask);
}
if (g->delay_accept) { /* Test of busy server */
sleep(g->delay_accept);
}
for (i = 0; i < num_sockets; i++)
if (FD_ISSET(g->listenfd[i],&read_mask)) {
if (do_accept(g, g->listenfd[i]) && g->active_conn < g->max_conn) {
/*
* The accept() succeeded, and we have at least one file
* descriptor still free, which means that another accept()
* could succeed. Go do do another select(), in case there
* are more incoming connections waiting to be accepted.
*/
goto select_again;
}
}
/* Check all open streams marked by select for data or a
close. We also close all open sockets except ALIVE
with no activity for a long period */
now = current_time(g);
for (i = 0; i < g->max_conn; i++) {
if (g->conn[i].open == EPMD_TRUE) {
if (FD_ISSET(g->conn[i].fd,&read_mask))
do_read(g,&g->conn[i]);
else if ((g->conn[i].keep == EPMD_FALSE) &&
((g->conn[i].mod_time + g->packet_timeout) < now)) {
dbg_tty_printf(g,1,"closing because timed out on receive");
epmd_conn_close(g,&g->conn[i]);
}
}
}
}
}
}
开发者ID:Eric-Zhong,项目名称:otp,代码行数:101,代码来源:epmd_srv.c
示例9: test_rw
//.........这里部分代码省略.........
cur_op = OP_WRITE;
tryout = blocks_at_once;
while (currently_testing < last_block) {
if (cancel_ops) goto out;
if (max_bb && bb_count >= max_bb) {
if (s_flag || v_flag) {
uprintf(abort_msg);
fprintf(log_fd, abort_msg);
fflush(log_fd);
}
cancel_ops = -1;
goto out;
}
if (currently_testing + tryout > last_block)
tryout = last_block - currently_testing;
if (detect_fakes) {
/* Add the block number at a fixed (random) offset during each pass to
allow for the detection of 'fake' media (eg. 2GB USB masquerading as 16GB) */
for (i=0; i<(int)blocks_at_once; i++) {
blk_id = (blk_t*)(intptr_t)(buffer + id_offset+ i*block_size);
*blk_id = (blk_t)(currently_testing + i);
}
}
got = do_write(hDrive, buffer, tryout, block_size, currently_testing);
if (v_flag > 1)
print_status();
if (got == 0 && tryout == 1)
bb_count += bb_output(currently_testing++, WRITE_ERROR);
currently_testing += got;
if (got != tryout) {
tryout = 1;
if (recover_block == ~0)
recover_block = currently_testing -
got + blocks_at_once;
continue;
} else if (currently_testing == recover_block) {
tryout = blocks_at_once;
recover_block = ~0;
}
}
num_blocks = 0;
if (s_flag | v_flag)
uprintf("%sReading and comparing\n", bb_prefix);
cur_op = OP_READ;
num_blocks = last_block;
currently_testing = first_block;
tryout = blocks_at_once;
while (currently_testing < last_block) {
if (cancel_ops) goto out;
if (max_bb && bb_count >= max_bb) {
if (s_flag || v_flag) {
uprintf(abort_msg);
fprintf(log_fd, abort_msg);
fflush(log_fd);
}
cancel_ops = -1;
goto out;
}
if (currently_testing + tryout > last_block)
tryout = last_block - currently_testing;
if (detect_fakes) {
for (i=0; i<(int)blocks_at_once; i++) {
blk_id = (blk_t*)(intptr_t)(buffer + id_offset+ i*block_size);
*blk_id = (blk_t)(currently_testing + i);
}
}
got = do_read(hDrive, read_buffer, tryout, block_size,
currently_testing);
if (got == 0 && tryout == 1)
bb_count += bb_output(currently_testing++, READ_ERROR);
currently_testing += got;
if (got != tryout) {
tryout = 1;
if (recover_block == ~0)
recover_block = currently_testing -
got + blocks_at_once;
continue;
} else if (currently_testing == recover_block) {
tryout = blocks_at_once;
recover_block = ~0;
}
for (i=0; i < got; i++) {
if (memcmp(read_buffer + i * block_size,
buffer + i * block_size,
block_size))
bb_count += bb_output(currently_testing+i-got, CORRUPTION_ERROR);
}
if (v_flag > 1)
print_status();
}
num_blocks = 0;
}
out:
free_buffer(buffer);
return bb_count;
}
开发者ID:Kronimo,项目名称:rufus,代码行数:101,代码来源:badblocks.c
示例10: main
//.........这里部分代码省略.........
if ((bitcount(commonbuses) > limitexceeded)) {
msg_pdbg("There is at least one interface available which could support the size of\n"
"the selected flash chip.\n");
}
msg_cerr("This flash chip is too big for this programmer (--verbose/-V gives details).\n"
"Use --force/-f to override at your own risk.\n");
ret = 1;
goto out_shutdown;
}
if (!(read_it | write_it | verify_it | erase_it)) {
msg_ginfo("No operations were specified.\n");
goto out_shutdown;
}
if (layoutfile) {
layout = get_global_layout();
} else if (ifd && (flashrom_layout_read_from_ifd(&layout, fill_flash, NULL, 0) ||
process_include_args(layout))) {
ret = 1;
goto out_shutdown;
} else if (fmap && fmapfile) {
struct stat s;
if (stat(fmapfile, &s) != 0) {
msg_gerr("Failed to stat fmapfile \"%s\"\n", fmapfile);
ret = 1;
goto out_shutdown;
}
size_t fmapfile_size = s.st_size;
uint8_t *fmapfile_buffer = malloc(fmapfile_size);
if (!fmapfile_buffer) {
ret = 1;
goto out_shutdown;
}
if (read_buf_from_file(fmapfile_buffer, fmapfile_size, fmapfile)) {
ret = 1;
free(fmapfile_buffer);
goto out_shutdown;
}
if (flashrom_layout_read_fmap_from_buffer(&layout, fill_flash, fmapfile_buffer, fmapfile_size) ||
process_include_args(layout)) {
ret = 1;
free(fmapfile_buffer);
goto out_shutdown;
}
free(fmapfile_buffer);
} else if (fmap && (flashrom_layout_read_fmap_from_rom(&layout, fill_flash, 0,
fill_flash->chip->total_size * 1024) || process_include_args(layout))) {
ret = 1;
goto out_shutdown;
}
flashrom_layout_set(fill_flash, layout);
flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE, !!force);
#if CONFIG_INTERNAL == 1
flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE_BOARDMISMATCH, !!force_boardmismatch);
#endif
flashrom_flag_set(fill_flash, FLASHROM_FLAG_VERIFY_AFTER_WRITE, !dont_verify_it);
flashrom_flag_set(fill_flash, FLASHROM_FLAG_VERIFY_WHOLE_CHIP, !dont_verify_all);
/* FIXME: We should issue an unconditional chip reset here. This can be
* done once we have a .reset function in struct flashchip.
* Give the chip time to settle.
*/
programmer_delay(100000);
if (read_it)
ret = do_read(fill_flash, filename);
else if (erase_it)
ret = do_erase(fill_flash);
else if (write_it)
ret = do_write(fill_flash, filename, referencefile);
else if (verify_it)
ret = do_verify(fill_flash, filename);
flashrom_layout_release(layout);
out_shutdown:
programmer_shutdown();
out:
for (i = 0; i < chipcount; i++)
free(flashes[i].chip);
layout_cleanup();
free(filename);
free(fmapfile);
free(referencefile);
free(layoutfile);
free(pparam);
/* clean up global variables */
free((char *)chip_to_probe); /* Silence! Freeing is not modifying contents. */
chip_to_probe = NULL;
#ifndef STANDALONE
free(logfile);
ret |= close_logfile();
#endif /* !STANDALONE */
return ret;
}
开发者ID:flashrom,项目名称:flashrom,代码行数:101,代码来源:cli_classic.c
示例11: main
int main(int argc, char *argv[]){
int quit;
char buf[80], prev;
if(argc < 2){
printf("%s <semid>\n", argv[0]);
return 1;
}
semid = atoi(argv[1]);
quit = 0;
while(!quit){
printf("\n> ");
fgets(buf, sizeof(buf), stdin);
switch(buf[0]){
case 'r':
case 'R':
prev = 'r';
do_read(buf);
break;
case 'w':
case 'W':
prev = 'w';
do_write(buf);
break;
case 'q':
case 'Q':
quit = 1;
break;
case 'h':
case 'H':
printf("Enter one of the following commands:\n");
printf("\tr - read a semaphore\n");
printf("\t\tsyntax r index[.level]\n");
printf("\t\te.g. r 1\n");
printf("\t\te.g. r 1.val\n");
printf("\tw - write a value\n");
printf("\t\tsyntax w index value\n");
printf("\t\te.g. w 1 7\n");
printf("\tq - quit\n");
break;
case '\r':
case '\n':
if(prev == 'r'){
sprintf(buf, "r %d\n", ++idx);
do_read(buf);
}
else if(prev == 'w'){
sprintf(buf, "w %d %d\n", ++idx, val);
do_write(buf);
}
break;
default:
break;
}
}
return 0;
}
开发者ID:B-Rich,项目名称:osf_db,代码行数:66,代码来源:8464_1.c
示例12: _elf32_load
static int _elf32_load(const char *filename, int fd, char *const argv[],
char *const envp[], uint32_t *eip, uint32_t *esp)
{
int err = 0;
Elf32_Ehdr header;
Elf32_Ehdr interpheader;
/* variables to clean up on failure */
vmmap_t *map = NULL;
file_t *file = NULL;
char *pht = NULL;
char *interpname = NULL;
int interpfd = -1;
file_t *interpfile = NULL;
char *interppht = NULL;
Elf32_auxv_t *auxv = NULL;
char *argbuf = NULL;
uintptr_t entry;
file = fget(fd);
KASSERT(NULL != file);
/* Load and verify the ELF header */
if (0 > (err = _elf32_load_ehdr(fd, &header, 0))) {
goto done;
}
if (NULL == (map = vmmap_create())) {
err = -ENOMEM;
goto done;
}
size_t phtsize = header.e_phentsize * header.e_phnum;
if (NULL == (pht = kmalloc(phtsize))) {
err = -ENOMEM;
goto done;
}
/* Read in the program header table */
if (0 > (err = _elf32_load_phtable(fd, &header, pht, phtsize))) {
goto done;
}
/* Load the segments in the program header table */
if (0 > (err = _elf32_map_progsegs(file->f_vnode, map, &header, pht, 0))) {
goto done;
}
Elf32_Phdr *phinterp = NULL;
/* Check if program requires an interpreter */
if (0 > (err = _elf32_find_phinterp(&header, pht, &phinterp))) {
goto done;
}
/* Calculate program bounds for future reference */
void *proglow;
void *proghigh;
_elf32_calc_progbounds(&header, pht, &proglow, &proghigh);
entry = (uintptr_t) header.e_entry;
/* if an interpreter was requested load it */
if (NULL != phinterp) {
/* read the file name of the interpreter from the binary */
if (0 > (err = do_lseek(fd, phinterp->p_offset, SEEK_SET))) {
goto done;
} else if (NULL == (interpname = kmalloc(phinterp->p_filesz))) {
err = -ENOMEM;
goto done;
} else if (0 > (err = do_read(fd, interpname, phinterp->p_filesz))) {
goto done;
}
if (err != (int)phinterp->p_filesz) {
err = -ENOEXEC;
goto done;
}
/* open the interpreter */
dbgq(DBG_ELF, "ELF Interpreter: %*s\n", phinterp->p_filesz, interpname);
if (0 > (interpfd = do_open(interpname, O_RDONLY))) {
err = interpfd;
goto done;
}
kfree(interpname);
interpname = NULL;
interpfile = fget(interpfd);
KASSERT(NULL != interpfile);
/* Load and verify the interpreter ELF header */
if (0 > (err = _elf32_load_ehdr(interpfd, &interpheader, 1))) {
goto done;
}
size_t interpphtsize = interpheader.e_phentsize * interpheader.e_phnum;
if (NULL == (interppht = kmalloc(interpphtsize))) {
err = -ENOMEM;
goto done;
}
/* Read in the program header table */
if (0 > (err = _elf32_load_phtable(interpfd, &interpheader, interppht, interpphtsize))) {
goto done;
//.........这里部分代码省略.........
开发者ID:Aliced3645,项目名称:os,代码行数:101,代码来源:elf32.c
示例13: wait_forward_request
/*
* Wait for all forward requests completion.
*
* Even if something goes wrong, we have to wait forward requests completion to
* avoid interleaved requests.
*
* Return error code if any one request fails.
*/
static int wait_forward_request(struct write_info *wi, struct request *req)
{
int nr_sent, err_ret = SD_RES_SUCCESS, ret, pollret, i,
repeat = MAX_RETRY_COUNT;
struct pfd_info pi;
struct sd_rsp *rsp = &req->rp;
again:
pfd_info_init(wi, &pi);
pollret = poll(pi.pfds, pi.nr, 1000 * POLL_TIMEOUT);
if (pollret < 0) {
if (errno == EINTR)
goto again;
panic("%m");
} else if (pollret == 0) {
/*
* If IO NIC is down, epoch isn't incremented, so we can't retry
* for ever.
*/
if (sheep_need_retry(req->rq.epoch) && repeat) {
repeat--;
sd_warn("poll timeout %d, disks of some nodes or "
"network is busy. Going to poll-wait again",
wi->nr_sent);
goto again;
}
nr_sent = wi->nr_sent;
/* XXX Blinedly close all the connections */
for (i = 0; i < nr_sent; i++)
sockfd_cache_del(wi->ent[i].nid, wi->ent[i].sfd);
return SD_RES_NETWORK_ERROR;
}
nr_sent = wi->nr_sent;
for (i = 0; i < nr_sent; i++)
if (pi.pfds[i].revents & POLLIN)
break;
if (i < nr_sent) {
int re = pi.pfds[i].revents;
sd_debug("%d, revents %x", i, re);
if (re & (POLLERR | POLLHUP | POLLNVAL)) {
err_ret = SD_RES_NETWORK_ERROR;
finish_one_write_err(wi, i);
goto finish_write;
}
if (do_read(pi.pfds[i].fd, rsp, sizeof(*rsp), sheep_need_retry,
req->rq.epoch, MAX_RETRY_COUNT)) {
sd_err("remote node might have gone away");
err_ret = SD_RES_NETWORK_ERROR;
finish_one_write_err(wi, i);
goto finish_write;
}
ret = rsp->result;
if (ret != SD_RES_SUCCESS) {
sd_err("fail %"PRIx64", %s", req->rq.obj.oid,
sd_strerror(ret));
err_ret = ret;
}
finish_one_write(wi, i);
}
finish_write:
if (wi->nr_sent > 0)
goto again;
return err_ret;
}
开发者ID:SongWuCloud,项目名称:ACStor,代码行数:77,代码来源:gateway.c
示例14: do_write
//.........这里部分代码省略.........
slot = i;
printf("select_slot slot %d\n", slot);
}
}
return slot;
}
static ulong get_block_size(char *ifname, int dev, int part)
{
block_dev_desc_t *dev_desc = NULL;
disk_partition_t part_info;
dev_desc = get_dev(ifname, dev);
if (dev_desc == NULL) {
printf("Block device %s %d not supported\n", ifname, dev);
return 0;
}
if (get_partition_info(dev_desc, part, &part_info)) {
printf("Cannot find partition %d\n", part);
return 0;
}
return part_info.blksz;
}
#define ALIGN_BYTES 64 /*armv7 cache line need 64 bytes aligned */
static int rw_block(bool bread, char **ppblock,
uint *pblksize, char *pblock_write)
{
int ret;
char *argv[6];
char addr_str[20];
char cnt_str[8];
char devpart_str[8];
char block_begin_str[8];
ulong blk_size = 0;
uint blk_begin = 0;
uint blk_end = 0;
uint block_cnt = 0;
char *p_block = NULL;
if (bread && ((ppblock == NULL) || (pblksize == NULL)))
return -1;
if (!bread && (pblock_write == NULL))
return -1;
blk_size = get_block_size("mmc", g_mmc_id,
CONFIG_ANDROID_MISC_PARTITION_MMC);
if (blk_size == 0) {
printf("rw_block, get_block_size return 0\n");
return -1;
}
blk_begin = BOOTCTRL_OFFSET/blk_size;
blk_end = (BOOTCTRL_OFFSET + sizeof(struct boot_ctl) - 1)/blk_size;
block_cnt = 1 + (blk_end - blk_begin);
sprintf(devpart_str, "0x%x:0x%x", g_mmc_id,
CONFIG_ANDROID_MISC_PARTITION_MMC);
sprintf(block_begin_str, "0x%x", blk_begin);
sprintf(cnt_str, "0x%x", block_cnt);
argv[0] = "rw"; /* not care */
argv[1] = "mmc";
argv[2] = devpart_str;
argv[3] = addr_str;
argv[4] = block_begin_str;
argv[5] = cnt_str;
if (bread) {
p_block = (char *)memalign(ALIGN_BYTES, blk_size * block_cnt);
if (NULL == p_block) {
printf("rw_block, memalign %d bytes failed\n",
(int)(blk_size * block_cnt));
return -1;
}
sprintf(addr_str, "0x%x", (unsigned int)p_block);
ret = do_read(NULL, 0, 6, argv);
if (ret) {
free(p_block);
printf("do_read failed, ret %d\n", ret);
return -1;
}
*ppblock = p_block;
*pblksize = (uint)blk_size;
} else {
sprintf(addr_str, "0x%x", (unsigned int)pblock_write);
ret = do_write(NULL, 0, 6, argv);
if (ret) {
printf("do_write failed, ret %d\n", ret);
return -1;
}
}
return 0;
}
开发者ID:flyingbing,项目名称:imx_uboot_v2015.04,代码行数:101,代码来源:bootctrl.c
示例15: rsh_loop
static int
rsh_loop (int s, int errsock)
{
fd_set real_readset;
int count = 1;
#ifdef KRB5
if(auth_method == AUTH_KRB5 && protocol_version == 2)
init_ivecs(1, errsock != -1);
#endif
if (s >= FD_SETSIZE || (errsock != -1 && errsock >= FD_SETSIZE))
errx (1, "fd too large");
FD_ZERO(&real_readset);
FD_SET(s, &real_readset);
if (errsock != -1) {
FD_SET(errsock, &real_readset);
++count;
}
if(input)
FD_SET(STDIN_FILENO, &real_readset);
for (;;) {
int ret;
fd_set readset;
char buf[RSH_BUFSIZ];
readset = real_readset;
ret = select (max(s, errsock) + 1, &readset, NULL, NULL, NULL);
if (ret < 0) {
if (errno == EINTR)
continue;
else
err (1, "select");
}
if (FD_ISSET(s, &readset)) {
ret = do_read (s, buf, sizeof(buf), ivec_in[0]);
if (ret < 0)
err (1, "read");
else if (ret == 0) {
close (s);
FD_CLR(s, &real_readset);
if (--count == 0)
return 0;
} else
net_write (STDOUT_FILENO, buf, ret);
}
if (errsock != -1 && FD_ISSET(errsock, &readset)) {
ret = do_read (errsock, buf, sizeof(buf), ivec_in[1]);
if (ret < 0)
err (1, "read");
else if (ret == 0) {
close (errsock);
FD_CLR(errsock, &real_readset);
if (--count == 0)
return 0;
} else
net_write (STDERR_FILENO, buf, ret);
}
if (FD_ISSET(STDIN_FILENO, &readset)) {
ret = read (STDIN_FILENO, buf, sizeof(buf));
if (ret < 0)
err (1, "read");
else if (ret == 0) {
close (STDIN_FILENO);
FD_CLR(STDIN_FILENO, &real_readset);
shutdown (s, SHUT_WR);
} else
do_write (s, buf, ret, ivec_out[0]);
}
}
}
开发者ID:SimonWilkinson,项目名称:heimdal,代码行数:73,代码来源:rsh.c
示例16: main
int main(int ac, char **av)
{
int lc;
int fd[2]; /* fds for pipe read/write */
char wrbuf[BUFSIZ], rebuf[BUFSIZ];
int red, written; /* no of chars read and */
/* written to pipe */
int length, greater, forkstat;
int retval = 0, status, e_code;
tst_parse_opts(ac, av, NULL, NULL);
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
/* reset tst_count in case we are looping */
tst_count = 0;
TEST(pipe(fd));
if (TEST_RETURN == -1) {
retval = 1;
tst_resm(TFAIL, "pipe creation failed");
continue;
}
strcpy(wrbuf, "abcdefghijklmnopqrstuvwxyz");
length = strlen(wrbuf) + 1;
written = write(fd[1], wrbuf, length);
/* did write write at least some chars */
if ((written < 0) || (written > length)) {
tst_brkm(TBROK, cleanup, "write to pipe failed");
}
forkstat = FORK_OR_VFORK();
if (forkstat == -1) {
tst_brkm(TBROK, cleanup, "fork() failed");
}
if (forkstat == 0) { /* child */
red = do_read(fd[0], rebuf, written);
/* did read , get at least some chars */
if ((red < 0) || (red > written)) {
tst_brkm(TBROK, cleanup, "read pipe failed");
}
greater = strcmp(rebuf, wrbuf);
/* are the strings written and read equal */
if (greater == 0) {
tst_resm(TPASS, "functionality is correct");
} else {
retval = 1;
tst_resm(TFAIL, "read & write strings do "
"not match");
}
exit(retval);
} else { /* parent */
/* wait for the child to finish */
wait(&status);
/* make sure the child returned a good exit status */
e_code = status >> 8;
if (e_code != 0) {
tst_resm(TFAIL, "Failures reported above");
}
}
}
cleanup();
tst_exit();
}
开发者ID:bsbrp,项目名称:ltp,代码行数:77,代码来源:pipe10.c
示例17: option_debug
//.........这里部分代码省略.........
};
//on_header_field
parser_settings_.on_header_field = [](http_parser* parser, const char* at, size_t len) {
auto psession = reinterpret_cast<http_session*>(parser->data);
if (psession->was_header_value_)
{
// new field started
if (!psession->last_header_field_.empty())
{
// add new entry
psession->request_.headers_[psession->last_header_field_] = psession->last_header_value_;
psession->last_header_value_.clear();
}
psession->last_header_field_ = std::string(at, len);
psession->was_header_value_ = false;
}
else
{
// appending
psession->last_header_field_ += std::string(at, len);
}
//std::cout << "on_header_field: " << std::string(at, len) << std::endl;
return 0;
};
//on_header_value
parser_settings_.on_header_value = [](http_parser* parser, const char* at, size_t len) {
auto psession = reinterpret_cast<http_session*>(parser->data);
if (!psession->was_header_value_)
{
psession->last_header_value_ = std::string(at, len);
psession->was_header_value_ = true;
}
else
{
// appending
psession->last_header_value_ += std::string(at, len);
}
//std::cout << "on_header_value: " << std::string(at, len) << std::endl;
return 0;
};
//on_headers_complete
parser_settings_.on_headers_complete = [](http_parser* parser) {
auto psession = reinterpret_cast<http_session*>(parser->data);
if (!psession->last_header_field_.empty()) {
// add new entry
psession->request_.headers_[psession->last_header_field_] = psession->last_header_value_;
}
return 0;
};
*/
//on_body
parser_settings_.on_body = [](http_parser* parser, const char* at, size_t len) {
auto psession = reinterpret_cast<http_session*>(parser->data);
psession->request_.body_ = const_cast<char*>(at);
psession->request_.len_ = len;
//std::cout << "on_body: " << std::string(at, len) << std::endl;
return 0;
};
parser_settings_.on_message_complete = [](http_parser* parser) {
auto psession = reinterpret_cast<http_session*>(parser->data);
bool bOK = psession->server_.invoke(psession->request_, psession->response_);
psession->process_ = true;
psession->do_write(psession->response_.end());
//std::cout << "on_message_complete: " << std::endl;
return 0;
};
//启动一个业务超时定时器,一个客户端,只允许他连接30秒,超过30秒就断开,无论有没有做完业务,时间可调。
std::weak_ptr<http_session> wp(shared_Derived_from_this<http_session>());
timer_.async_wait([wp](const boost::system::error_code& ec){
if (ec != boost::asio::error::operation_aborted)
{
//定时器回调函数返回,但是不是定时器被取消,那么就关闭socket。
//定期器被取消,是个正常操作
auto sp(wp.lock());
if (sp)
{
sp->close();
}
}
});
do_read();
}
开发者ID:caosonglin,项目名称:MyWarehouse,代码行数:101,代码来源:http_session.cpp
示例18: echo_test
static void
echo_test(void * p)
{
int s_source, s_sink, e_source, e_sink;
struct sockaddr_in e_source_addr, e_sink_addr, local;
int one = 1;
fd_set in_fds;
int i, num, len;
struct test_params params,nparams;
struct test_status status,nstatus;
s_source = socket(AF_INET, SOCK_STREAM, 0);
if (s_source < 0) {
pexit("stream socket");
}
if (setsockopt(s_source, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
pexit("setsockopt /source/ SO_REUSEADDR");
}
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
// local.sin_len = sizeof(local);
local.sin_port = ntohs(SOURCE_PORT);
local.sin_addr.s_addr = INADDR_ANY;
if(bind(s_source, (struct sockaddr *) &local, sizeof(local)) < 0) {
pexit("bind /source/ error");
}
listen(s_source, SOMAXCONN);
s_sink = socket(AF_INET, SOCK_STREAM, 0);
if (s_sink < 0) {
pexit("stream socket");
}
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
// local.sin_len = sizeof(local);
local.sin_port = ntohs(SINK_PORT);
local.sin_addr.s_addr = INADDR_ANY;
if(bind(s_sink, (struct sockaddr *) &local, sizeof(local)) < 0) {
pexit("bind /sink/ error");
}
if (setsockopt(s_sink, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) {
pexit("setsockopt /sink/ SO_REUSEADDR");
}
listen(s_sink, SOMAXCONN);
e_source = 0; e_sink = 0;
while (true) {
// Wait for a connection on either of the ports
FD_ZERO(&in_fds);
FD_SET(s_source, &in_fds);
FD_SET(s_sink, &in_fds);
num = select(max(s_sink,s_source)+1, &in_fds, 0, 0, 0);
if (FD_ISSET(s_source, &in_fds)) {
len = sizeof(e_source_addr);
if ((e_source = accept(s_source, (struct sockaddr *)&e_source_addr, &len)) < 0) {
pexit("accept /source/");
}
diag_printf("SOURCE connection from %s:%d\n",
inet_ntoa(e_source_addr.sin_addr), ntohs(e_source_addr.sin_port));
}
if (FD_ISSET(s_sink, &in_fds)) {
len = sizeof(e_sink_addr);
if ((e_sink = accept(s_sink, (struct sockaddr *)&e_sink_addr, &len)) < 0) {
pexit("accept /sink/");
}
diag_printf("SINK connection from %s:%d\n",
inet_ntoa(e_sink_addr.sin_addr), ntohs(e_sink_addr.sin_port));
}
// Continue with test once a connection is established in both directions
if ((e_source != 0) && (e_sink != 0)) {
break;
}
}
// Wait for "source" to tell us the testing paramters
if (do_read(e_source, &nparams, sizeof(nparams)) != sizeof(nparams)) {
pexit("Can't read initialization parameters");
}
params.nbufs = ntohl(nparams.nbufs);
params.bufsize = ntohl(nparams.bufsize);
params.load = ntohl(nparams.load);
diag_printf("Using %d buffers of %d bytes each, %d%% background load\n",
params.nbufs, params.bufsize, params.load);
// Tell the sink what the parameters are
if (do_write(e_sink, &nparams, sizeof(nparams)) != sizeof(nparams)) {
pexit("Can't write initialization parameters");
}
status.ok = 1;
nstatus.ok = htonl(status.ok);
// Tell the "source" to start - we're all connected and ready to go!
if (do_write(e_source, &nstatus, sizeof(nstatus)) != sizeof(nstatus)) {
pexit("Can't send ACK to 'source' host");
}
T
|
请发表评论