青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Prayer

在一般中尋求卓越
posts - 1256, comments - 190, trackbacks - 0, articles - 0
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

aio_read template.

Posted on 2009-04-02 10:35 Prayer 閱讀(973) 評論(0)  編輯 收藏 引用 所屬分類: C/C++LINUX/UNIX/AIX
Volker,
Here is a template for the way we'd use aio_read within Samba3.
Seems to work well on 2.6 kernels. It's a standalone program that will
copy a file using aio_read. The one thing I haven't coped with is a
short read from aio_read (not an EOF read, but just reading less bytes
than we asked for). I'm not sure if this is possible with the aio_read
interface but thought I'd just warn you....
Hopefully you'll find this useful.
Jeremy.
-------------- next part --------------
/*
Sample aio_read code as would be used in Samba3.
Copyright (C) Jeremy Allison, 2005.
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <time.h>
#include <strings.h>
#include <aio.h>
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b)?(a):(b))
#endif
int set_blocking(int fd, int set)
{
int val;
if((val = fcntl(fd, F_GETFL, 0)) == -1)
return -1;
if(set) /* Turn blocking on - ie. clear nonblock flag */
val &= ~O_NONBLOCK;
else
val |= O_NONBLOCK;
return fcntl( fd, F_SETFL, val);
}
static pid_t initialised;
static int select_pipe[2];
static volatile unsigned pipe_written, pipe_read;
/*******************************************************************
Call this from all Samba signal handlers if you want to avoid a
nasty signal race condition.
********************************************************************/
void sys_select_signal(void)
{
char c = 1;
if (!initialised) {
return;
}
if (pipe_written > pipe_read+256) {
return;
}
if (write(select_pipe[1], &c, 1) == 1) {
pipe_written++;
}
}
/*******************************************************************
Like select() but avoids the signal race using a pipe
it also guuarantees that fds on return only ever contains bits set
for file descriptors that were readable.
********************************************************************/
int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval)
{
int ret, saved_errno;
fd_set *readfds2, readfds_buf;
if (initialised != getpid()) {
pipe(select_pipe);
/*
* These next two lines seem to fix a bug with the Linux
* 2.0.x kernel (and probably other UNIXes as well) where
* the one byte read below can block even though the
* select returned that there is data in the pipe and
* the pipe_written variable was incremented. Thanks to
* HP for finding this one. JRA.
*/
if(set_blocking(select_pipe[0],0)==-1)
exit(1);
if(set_blocking(select_pipe[1],0)==-1)
exit(1);
initialised = getpid();
}
maxfd = MAX(select_pipe[0]+1, maxfd);
/* If readfds is NULL we need to provide our own set. */
if (readfds) {
readfds2 = readfds;
} else {
readfds2 = &readfds_buf;
FD_ZERO(readfds2);
}
FD_SET(select_pipe[0], readfds2);
errno = 0;
ret = select(maxfd,readfds2,writefds,errorfds,tval);
if (ret <= 0) {
FD_ZERO(readfds2);
if (writefds)
FD_ZERO(writefds);
if (errorfds)
FD_ZERO(errorfds);
} else if (FD_ISSET(select_pipe[0], readfds2)) {
char c;
saved_errno = errno;
if (read(select_pipe[0], &c, 1) == 1) {
pipe_read++;
/* Mark Weaver <mark-clist at npsl.co.uk> pointed out a critical
fix to ensure we don't lose signals. We must always
return -1 when the select pipe is set, otherwise if another
fd is also ready (so ret == 2) then we used to eat the
byte in the pipe and lose the signal. JRA.
*/
ret = -1;
errno = EINTR;
} else {
FD_CLR(select_pipe[0], readfds2);
ret--;
errno = saved_errno;
}
}
return ret;
}
void BlockSignals(int block,int signum)
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set,signum);
sigprocmask(block?SIG_BLOCK:SIG_UNBLOCK,&set,NULL);
}
#define SIG_AIO_READ_DONE (SIGRTMIN)
#define AIO_PENDING_SIZE 10
static sig_atomic_t signals_received;
static struct aiocb aio_pending_array[AIO_PENDING_SIZE];
static void process_completed_read(int fd_out, char *buf, off_t *p_curr_off, int *p_finished)
{
struct aiocb a;
ssize_t nbytes_read;
BlockSignals(1, SIG_AIO_READ_DONE);
a = aio_pending_array[0];
memset(&aio_pending_array[0], '\0', sizeof(a));
if (signals_received > 1) {
memmove(&aio_pending_array[0],
&aio_pending_array[1],
sizeof(a)*(signals_received-1));
}
signals_received--;
/* now we can receive more signals */
BlockSignals(0, SIG_AIO_READ_DONE);
nbytes_read = aio_return(&a);
if (nbytes_read == -1) {
fprintf(stderr, "Error in aio_read: %s\n", strerror(errno) );
exit(1);
}
if (nbytes_read == 0) {
/* End of file. */
*p_finished = 1;
return;
}
if (pwrite(fd_out, buf, nbytes_read, *p_curr_off) != nbytes_read) {
fprintf(stderr, "Error in write: %s\n", strerror(errno) );
exit(1);
}
*p_curr_off += nbytes_read;
printf("New offset = 0x%x\n", *p_curr_off);
}
static void schedule_aio_read(struct aiocb *a, int fd_in, char *buf, size_t bufsize, off_t cur_offset)
{
memset(a, '\0', sizeof(struct aiocb));
a->aio_fildes = fd_in;
a->aio_buf = buf;
a->aio_nbytes = bufsize;
a->aio_offset = cur_offset;
a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
a->aio_sigevent.sigev_signo  = SIG_AIO_READ_DONE;
a->aio_sigevent.sigev_value.sival_ptr = (void *)a;
aio_read(a);
}
static void signal_handler(int sig, siginfo_t *info, void *unused)
{
if (signals_received < AIO_PENDING_SIZE - 1) {
aio_pending_array[signals_received] = *(struct aiocb *)(info->si_value.sival_ptr);
signals_received++;
} /* Else signal is lost. */
sys_select_signal();
}
int main(int argc, char **argv)
{
int fd_in;
int fd_out;
sigset_t io_set;
struct sigaction sa;
int finished = 0;
int schedule_next_read = 1;
off_t curr_offset = 0;
struct timeval tval;
struct aiocb a;
char buf[4096];
if (argc != 3) {
printf("Usage: %s fromfile tofile\n");
exit(1);
}
fd_in = open(argv[1], O_RDONLY);
if (fd_in == -1) {
fprintf(stderr, "open of %s failed: %s\n", argv[1], strerror(errno));
exit(1);
}
fd_out = open(argv[2], O_CREAT|O_TRUNC|O_RDWR, 0644);
if (fd_out == -1) {
fprintf(stderr, "open of %s failed: %s\n", argv[2], strerror(errno));
exit(1);
}
memset(&sa, '\0', sizeof(struct sigaction));
sa.sa_sigaction = signal_handler;
sa.sa_flags = SA_RESTART|SA_SIGINFO;
//sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIG_AIO_READ_DONE);
if (sigaction( SIG_AIO_READ_DONE, &sa, NULL) == -1) {
fprintf(stderr, "sigaction failed: %s\n", strerror(errno));
exit(1);
}
/* Ensure the signal pipe exists before we start the aio so we don't
lose the signal write down the pipe (which we would if the pipe hadn't
been created. This isn't a problem in a real smbd. */
tval.tv_sec = 0;
tval.tv_usec = 0;
sys_select(0,NULL,NULL,NULL,&tval);
while (!finished) {
int ret;
if (schedule_next_read) {
schedule_aio_read(&a, fd_in,buf,sizeof(buf),curr_offset);
schedule_next_read = 0;
}
printf("signals_received = %d\n", signals_received);
ret = sys_select(0,NULL,NULL,NULL,NULL);
if (signals_received && ret == -1 && errno == EINTR) {
process_completed_read(fd_out, buf, &curr_offset, &finished);
schedule_next_read = 1;
}
}
close(fd_in);
close(fd_out);
return 0;
}
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久久久久久久久久久久女国产乱 | 欧美电影免费观看大全| 亚洲一区二区3| 亚洲视频你懂的| 亚洲综合色在线| 欧美综合激情网| 欧美91大片| 国产精品v亚洲精品v日韩精品| 欧美日韩午夜剧场| 国产精品亚发布| 在线播放中文一区| 一二三区精品| 欧美一区亚洲| 六月婷婷一区| 日韩视频不卡| 香蕉尹人综合在线观看| 麻豆精品精华液| 国产精品激情电影| 亚洲成人在线| 香蕉成人久久| 亚洲国产精品久久久| 欧美国产综合| 亚洲中字在线| 欧美激情在线观看| 激情成人亚洲| 亚洲一二区在线| 欧美成年人视频网站| 中文精品一区二区三区| 久久综合导航| 国产日韩三区| 中文欧美日韩| 亚洲国产精品久久久久久女王| 欧美亚洲一区二区在线| 欧美精品色一区二区三区| 国产视频亚洲| 亚洲午夜国产一区99re久久| 美女主播一区| 欧美一级二级三级蜜桃| 欧美精品激情| 最新热久久免费视频| 久久久青草青青国产亚洲免观| 亚洲美女黄色| 欧美—级在线免费片| 在线观看视频免费一区二区三区| 性做久久久久久久免费看| av成人福利| 欧美日韩在线电影| 夜夜狂射影院欧美极品| 亚洲成色999久久网站| 久久久国产午夜精品| 国产日韩欧美一区在线| 午夜久久tv| 亚洲午夜一二三区视频| 欧美日韩亚洲一区三区| 亚洲精品一区久久久久久| 免费在线看成人av| 久久久久五月天| 好吊日精品视频| 久久久久久一区二区三区| 亚洲视频免费观看| 国产精品私房写真福利视频| 亚洲无限乱码一二三四麻| 夜夜嗨av一区二区三区免费区| 欧美国产日韩亚洲一区| 日韩视频永久免费| 亚洲精品黄网在线观看| 欧美日韩系列| 亚洲欧美日韩另类精品一区二区三区| 日韩视频精品在线| 国产精品扒开腿爽爽爽视频| 先锋资源久久| 久久久久久一区| 亚洲日本一区二区| 亚洲精品国产欧美| 国产精品国内视频| 久久全球大尺度高清视频| 久久久xxx| 日韩视频精品| 亚洲一区免费看| 今天的高清视频免费播放成人 | 日韩一区二区精品| 国产精品手机在线| 免费在线视频一区| 欧美日韩精品欧美日韩精品| 亚洲欧美日本国产专区一区| 午夜亚洲福利| 亚洲国产视频直播| 一本久久青青| 韩日视频一区| 夜夜嗨av一区二区三区网页 | 久热综合在线亚洲精品| 夜夜夜久久久| 久久久久成人精品| 这里只有视频精品| 久久精品卡一| 亚洲午夜国产成人av电影男同| 欧美一区二区三区男人的天堂| 亚洲二区在线观看| 亚洲一区精品电影| 亚洲精品日韩激情在线电影| 亚洲一区二区视频在线| 91久久久精品| 欧美一区二区三区四区视频| 日韩一级不卡| 久久久久久久精| 欧美一区不卡| 欧美日韩色婷婷| 欧美激情久久久| 国产一区导航| 亚洲自拍啪啪| 亚洲视频网站在线观看| 久久天天躁夜夜躁狠狠躁2022| 亚洲欧美精品| 欧美日产国产成人免费图片| 久久久噜噜噜| 国产欧美日韩亚洲精品| 日韩视频永久免费| 亚洲精品美女在线观看播放| 欧美一区二区三区免费观看视频| 99伊人成综合| 欧美大片网址| 欧美激情偷拍| 在线免费观看成人网| 久久岛国电影| 久久久91精品| 国产视频亚洲精品| 亚洲视频导航| 亚洲影院色在线观看免费| 欧美片第一页| 亚洲精品精选| 日韩性生活视频| 免费成人性网站| 看欧美日韩国产| 国产在线高清精品| 亚洲欧美高清| 欧美一区永久视频免费观看| 欧美日在线观看| 欧美激情一级片一区二区| 玉米视频成人免费看| 久久久久99| 欧美二区在线看| 亚洲人成网站在线观看播放| 牛人盗摄一区二区三区视频| 亚洲第一主播视频| 亚洲精品一线二线三线无人区| 欧美交受高潮1| 一本一道久久综合狠狠老精东影业 | 欧美成人免费网站| 亚洲精品国产精品国自产观看 | 欧美日韩国产小视频| 亚洲三级影片| 午夜电影亚洲| 国产一区二区视频在线观看| 久久狠狠亚洲综合| 麻豆国产精品va在线观看不卡| 在线观看欧美黄色| 欧美精品日韩精品| 亚洲一区二区三区777| 欧美一区二区私人影院日本| 国内在线观看一区二区三区| 久久久久久9| 亚洲三级网站| 久久精品一区二区三区不卡牛牛 | 亚洲高清视频的网址| 亚洲网站啪啪| 海角社区69精品视频| 欧美国产大片| 亚洲主播在线| 亚洲电影免费在线 | 欧美性淫爽ww久久久久无| 午夜国产精品视频| 亚洲国产精品999| 欧美一级在线播放| 在线看成人片| 国产女主播在线一区二区| 久久另类ts人妖一区二区| 日韩午夜电影在线观看| 久久久另类综合| 亚洲在线视频| 亚洲激情专区| 国产有码在线一区二区视频| 欧美日韩国产综合网 | 正在播放亚洲一区| 欧美成人免费va影院高清| 亚洲免费一级电影| 亚洲成人影音| 国产视频在线观看一区| 欧美精品一二三| 久久久久久久一区| 亚洲午夜精品视频| 亚洲国产精品久久久| 久久亚洲欧美| 久久xxxx精品视频| 亚洲一品av免费观看| 亚洲国产一区在线| 一区二区在线视频播放| 国产精品三上| 国产精品va| 欧美日韩综合| 欧美日韩精品在线视频|