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

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>
            一区二区三区精密机械公司| 亚洲天堂黄色| 欧美国产日韩一区二区| 久久精品国产99| 欧美在线观看一区| 久久亚裔精品欧美| 欧美成人嫩草网站| 亚洲日本va午夜在线电影| 麻豆精品国产91久久久久久| 久久久久久91香蕉国产| 欧美亚洲日本网站| 欧美在线不卡| 麻豆9191精品国产| 一本色道久久综合亚洲精品按摩| 亚洲久久在线| 午夜一区二区三视频在线观看 | 欧美一级夜夜爽| 久久综合狠狠综合久久激情| 亚洲黄色在线视频| 亚洲一品av免费观看| 久久精品夜色噜噜亚洲aⅴ| 欧美激情视频在线播放| 国产精品无码永久免费888| 在线免费观看视频一区| 亚洲综合首页| 欧美成人精品h版在线观看| 夜夜爽99久久国产综合精品女不卡| 亚洲欧美中文在线视频| 欧美激情综合五月色丁香| 国产精品视频专区| 亚洲麻豆一区| 久久综合色8888| 亚洲一区二区三区四区五区黄| 久久精品国产亚洲一区二区| 欧美日本一道本在线视频| 极品尤物久久久av免费看| 夜夜爽www精品| 亚洲一二三区在线| 欧美高清在线精品一区| 国产亚洲a∨片在线观看| 一区二区三区免费看| 久久中文字幕导航| 亚洲伊人色欲综合网| 欧美日韩精品福利| 日韩图片一区| 亚洲成人在线网| 久久精品99国产精品日本| 国产精品久久久久国产a级| 一区二区激情视频| 91久久午夜| 欧美精品色综合| 亚洲欧洲在线播放| 欧美成人一品| 看片网站欧美日韩| 亚洲大胆美女视频| 免费亚洲一区二区| 免费日韩视频| 日韩亚洲视频在线| 亚洲区一区二区三区| 欧美国产视频一区二区| 亚洲国产欧美在线| 亚洲国产综合91精品麻豆| 免费欧美在线| av成人免费在线观看| 亚洲欧洲日夜超级视频| 欧美激情一区在线观看| 夜夜爽www精品| 野花国产精品入口| 国产精品入口夜色视频大尺度| 亚洲一区一卡| 性亚洲最疯狂xxxx高清| 国内久久视频| 噜噜噜在线观看免费视频日韩| 久久九九全国免费精品观看| 精品不卡在线| 亚洲国产网站| 欧美午夜精品久久久久久久| 亚洲制服av| 新片速递亚洲合集欧美合集| 樱桃国产成人精品视频| 亚洲欧洲一区二区三区| 欧美色区777第一页| 久久久精品动漫| 久久夜色精品国产欧美乱极品 | 欧美日韩免费一区| 午夜日韩激情| 久久一二三四| 亚洲影院免费观看| 久久精品国产久精国产爱| 最新亚洲电影| 亚洲欧美激情精品一区二区| 91久久久久久| 亚洲视频电影图片偷拍一区| 黄色成人在线免费| 亚洲免费精彩视频| 国产亚洲人成a一在线v站| 在线精品观看| 亚洲在线观看视频| 午夜精品电影| 亚洲精品中文字| 小黄鸭视频精品导航| 日韩视频一区二区三区| 午夜视频在线观看一区二区| 亚洲日韩欧美视频| 欧美亚洲视频一区二区| 在线亚洲一区| 久久综合狠狠综合久久综合88| 亚洲一区二区三区精品在线| 久久精品在线免费观看| 亚洲欧美日韩国产成人| 欧美电影免费观看| 久久夜色精品国产噜噜av| 欧美日韩一级视频| 亚洲国产激情| 亚洲国产高清一区二区三区| 亚洲欧美日韩人成在线播放| 亚洲精品乱码久久久久久蜜桃91 | 毛片精品免费在线观看| 国产精品你懂的| 日韩视频不卡| 亚洲激情电影在线| 久久九九久精品国产免费直播| 亚洲欧美综合另类中字| 欧美视频在线观看免费网址| 亚洲国产精品成人精品| 精品动漫3d一区二区三区免费版| av72成人在线| 亚洲色图综合久久| 欧美日本国产视频| 亚洲精品日韩激情在线电影| 亚洲激情在线| 欧美国产综合| 亚洲精品视频在线看| 一区二区三区精品久久久| 免费视频一区| 亚洲黑丝在线| 在线亚洲一区二区| 欧美色综合网| 亚洲一区二区三区四区在线观看| 亚洲一区二区三区精品动漫| 欧美天堂亚洲电影院在线播放| 999亚洲国产精| 亚洲综合色激情五月| 国产精品久久久久久久久久三级 | 黄色成人av在线| 久久久之久亚州精品露出| 免播放器亚洲| 亚洲精品一区二区三区四区高清| 久色成人在线| 亚洲欧洲日本mm| 午夜精品免费在线| 国产日韩在线视频| 久久亚洲精品伦理| 亚洲国产日韩美| 亚洲小视频在线| 91久久精品www人人做人人爽| 亚洲国产成人91精品| 美女国内精品自产拍在线播放| 亚洲国产成人久久综合| 亚洲精品在线三区| 国产精品久久久久9999高清| 亚洲欧美制服另类日韩| 老司机午夜精品| 一区二区三区产品免费精品久久75 | 久久久久久综合| 免费黄网站欧美| 一区二区亚洲欧洲国产日韩| 久色成人在线| 一区二区三区高清在线观看| 欧美一区影院| 亚洲精品精选| 国产精品久久久久久久电影 | 欧美午夜不卡影院在线观看完整版免费| 一区二区高清视频| 美女脱光内衣内裤视频久久影院 | 国模吧视频一区| 欧美精品一区二区三区在线看午夜 | 狠狠爱www人成狠狠爱综合网| 欧美在线资源| 亚洲人成啪啪网站| 久久精品亚洲国产奇米99| 亚洲精品美女久久久久| 国产婷婷精品| 国产精品美女久久久浪潮软件 | 一区二区三区四区蜜桃| 免费不卡欧美自拍视频| 午夜亚洲福利| 日韩系列在线| 一区二区亚洲精品国产| 国产精品国产一区二区| 久久久久久夜精品精品免费| 在线亚洲国产精品网站| 亚洲国产91精品在线观看| 久色成人在线| 久久久国产一区二区| 午夜精品久久久久久久99樱桃| 亚洲精品一区中文| 亚洲电影视频在线| 1024日韩| 影音先锋另类|