本文整理汇总了C++中do_close函数的典型用法代码示例。如果您正苦于以下问题:C++ do_close函数的具体用法?C++ do_close怎么用?C++ do_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_close函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: rktio_close_noerr
void rktio_close_noerr(rktio_t *rktio, rktio_fd_t *rfd)
{
(void)do_close(rktio, rfd, 0);
}
开发者ID:97jaz,项目名称:racket,代码行数:4,代码来源:rktio_fd.c
示例2: dbg
void *extra_self_tests(int arg1, void *arg2)
{
/* creating /test1/test2/ directories */
dbg(DBG_ERROR | DBG_VFS,"TEST: Creating directories\n");
do_mkdir("dir");
do_mkdir("dir/dir1");
do_mkdir("dir/dir2");
do_mkdir("dir/dir3");
do_mkdir("dir/dir4");
dbg(DBG_ERROR | DBG_VFS,"TEST: Directories are created\n");
int fd;
char *file2buf="File 2 write only test case";
char *file1buf="Testing file_1 for write operation";
char readbuf[150];
dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir1\n");
do_chdir("dir/dir1");
/* file1.txt creation with O_CREAT|O_WRONLY flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Create file1.txt with O_CREAT|O_WRONLY flag in directory dir/dir1\n");
fd = do_open("file1.txt", O_CREAT|O_WRONLY);
do_write(fd, file1buf, strlen(file1buf));
do_close(fd);
/* file2.txt creation with O_CREAT|O_RDONLY flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Change directory to dir/dir2\n");
do_chdir("/dir/dir2");
dbg(DBG_ERROR | DBG_VFS,"TEST: Create file2.txt with O_CREAT | O_RDONLY flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_CREAT | O_RDONLY);
do_close(fd);
/* Write into file2.txt using O_WRONLY flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Write into file2.txt with O_WRONLY flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_WRONLY);
do_write(fd, file2buf, strlen(file2buf));
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: written chars: \"%s\" in file2.txt\n",file2buf);
char *appendbuf=" Appending for O_WRONLY|O_APPEND mode";
/* Append into file2.txt using O_WRONLY|O_APPEND flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_WRONLY|O_APPEND flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_WRONLY|O_APPEND);
do_write(fd, appendbuf, strlen(appendbuf));
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",appendbuf);
fd = do_open("file2.txt", O_RDONLY);
memset(readbuf,0,sizeof(char)*150);
do_read(fd,readbuf,strlen(file2buf)+strlen(appendbuf));
dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf);
char *append2buf=" Appending for O_RDWR|O_APPEND mode in file2";
/* Append into file2.txt using O_RDWR|O_APPEND flag*/
dbg(DBG_ERROR | DBG_VFS,"TEST: Append into file2.txt with O_RDWR|O_APPEND flag in directory dir/dir2\n");
fd = do_open("file2.txt", O_RDWR|O_APPEND);
do_write(fd, append2buf, strlen(append2buf));
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: Appending chars: \"%s\" in file2.txt\n",append2buf);
fd = do_open("file2.txt", O_RDONLY);
memset(readbuf,0,sizeof(char)*150);
do_read(fd,readbuf,strlen(file2buf)+strlen(append2buf)+strlen(appendbuf));
dbg(DBG_ERROR | DBG_VFS,"TEST: After Appending text in file2.txt is: \"%s\" \n",readbuf);
dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source directory => /dir/dir2, Destination directory => /dir/linkofdir2 \n");
do_chdir("/");
do_link("dir/dir2","dir/linkofdir2");
dbg(DBG_ERROR | DBG_VFS,"TEST:Linking Source file => /dir/dir1/file1.txt, to the Destination => /dir/linkoffile1 \n");
do_link("dir/dir1/file1.txt","dir/linkoffile1");
dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming directory from dir/dir3 to dir/renamed \n");
do_rename("dir/dir3","dir/renameddir3");
dbg(DBG_ERROR | DBG_VFS,"TEST: Renaming file from dir/dir1/file1.txt to dir/dir1/renamedfile1.txt \n");
do_rename("dir/dir1/file1.txt","dir/dir1/renamedfile1.txt");
dbg(DBG_ERROR | DBG_VFS,"TEST: Removing directory dir/dir4 \n");
do_rmdir("dir/dir4");
dbg(DBG_ERROR | DBG_VFS,"TEST: reading 18 chars from file: /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n");
fd = do_open("dir/linkoffile2", O_RDONLY);
memset(readbuf,0,sizeof(char)*150);
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: read 18 chars: \"%s\" from file: /dir/linkoffile1\n",readbuf);
dbg(DBG_ERROR | DBG_VFS,"TEST: reading file using lseek function on /dir/linkoffile2 which is hard link of /dir/dir2/file2.txt \n");
memset(readbuf,0,sizeof(char)*150);
fd = do_open("dir/linkoffile2", O_RDONLY);
do_lseek(fd,-19,2);
do_read(fd,readbuf,19);
do_close(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: read chars: \"%s\" using lseek from file: /dir/linkoffile1\n",readbuf);
dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup()\n");
fd = do_open("/dir/dir2/file2.txt", O_RDONLY);
int fd2= do_dup(fd);
dbg(DBG_ERROR | DBG_VFS,"TEST: duplicate file descriptor is :\"%d\" of file: /dir/dir2/file2.txt \n",fd2);
do_close(fd); do_close(fd2);
dbg(DBG_ERROR | DBG_VFS,"TEST: creating a duplicate file descriptor of file: /dir/dir2/file2.txt using do_dup2()\n");
//.........这里部分代码省略.........
开发者ID:jiangchhz,项目名称:abmp,代码行数:101,代码来源:kmain.c
示例3: do_send_file
static void do_send_file(struct st_h2o_sendfile_generator_t *self, h2o_req_t *req, int status, const char *reason,
h2o_iovec_t mime_type, h2o_mime_attributes_t *mime_attr, int is_get)
{
/* link the request */
self->req = req;
/* setup response */
req->res.status = status;
req->res.reason = reason;
req->res.content_length = self->bytesleft;
req->res.mime_attr = mime_attr;
if (self->ranged.range_count > 1) {
mime_type.base = h2o_mem_alloc_pool(&req->pool, 52);
mime_type.len = sprintf(mime_type.base, "multipart/byteranges; boundary=%s", self->ranged.boundary.base);
}
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_TYPE, mime_type.base, mime_type.len);
h2o_filecache_get_last_modified(self->file.ref, self->header_bufs.last_modified);
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_LAST_MODIFIED, self->header_bufs.last_modified,
H2O_TIMESTR_RFC1123_LEN);
add_headers_unconditional(self, req);
if (self->content_encoding.base != NULL)
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_ENCODING, self->content_encoding.base,
self->content_encoding.len);
if (self->ranged.range_count == 0)
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_ACCEPT_RANGES, H2O_STRLIT("bytes"));
else if (self->ranged.range_count == 1) {
h2o_iovec_t content_range;
content_range.base = h2o_mem_alloc_pool(&req->pool, 128);
content_range.len = sprintf(content_range.base, "bytes %zd-%zd/%zd", self->ranged.range_infos[0],
self->ranged.range_infos[0] + self->ranged.range_infos[1] - 1, self->ranged.filesize);
h2o_add_header(&req->pool, &req->res.headers, H2O_TOKEN_CONTENT_RANGE, content_range.base, content_range.len);
}
/* special path for cases where we do not need to send any data */
if (!is_get || self->bytesleft == 0) {
static h2o_generator_t generator = {NULL, NULL};
h2o_start_response(req, &generator);
h2o_send(req, NULL, 0, 1);
do_close(&self->super, req);
return;
}
/* send data */
h2o_start_response(req, &self->super);
if (self->ranged.range_count == 1)
self->file.off = self->ranged.range_infos[0];
if (req->_ostr_top->start_pull != NULL && self->ranged.range_count < 2) {
req->_ostr_top->start_pull(req->_ostr_top, do_pull);
} else {
size_t bufsz = MAX_BUF_SIZE;
if (self->bytesleft < bufsz)
bufsz = self->bytesleft;
self->buf = h2o_mem_alloc_pool(&req->pool, bufsz);
if (self->ranged.range_count < 2)
do_proceed(&self->super, req);
else {
self->bytesleft = 0;
self->super.proceed = do_multirange_proceed;
do_multirange_proceed(&self->super, req);
}
}
}
开发者ID:ancuop,项目名称:h2o,代码行数:64,代码来源:file.c
示例4: imc_idle_select
/* low-level idle function: read/write buffers as needed, etc */
void imc_idle_select(fd_set *read, fd_set *write, fd_set *exc, time_t now)
{
const char *command;
imc_packet *p;
imc_connect *c, *c_next ;
if (imc_active<IA_CONFIG1)
return;
if (imc_lock)
{
imc_logerror("imc_idle_select: recursive call");
return;
}
imc_lock=1;
if (imc_sequencenumber < (unsigned long)imc_now)
imc_sequencenumber=(unsigned long)imc_now;
imc_run_events(now);
if (imc_active<IA_UP)
{
imc_lock=0;
return;
}
/* handle results of the select */
if (imc_active >= IA_LISTENING &&
FD_ISSET(control, read))
do_accept();
for (c=imc_connect_list; c; c=c_next)
{
c_next=c->next;
if (c->state!=IMC_CLOSED && FD_ISSET(c->desc, exc))
do_close(c);
if (c->state!=IMC_CLOSED && FD_ISSET(c->desc, read))
do_read(c);
while (c->state!=IMC_CLOSED &&
// (c->spamtime1>=0 || c->spamcounter1<=IMC_SPAM1MAX) &&
// (c->spamtime2>=0 || c->spamcounter2<=IMC_SPAM2MAX) &&
(command = get_one_line(c->inbuf)) != NULL)
{
if (strlen(command) > imc_stats.max_pkt)
imc_stats.max_pkt=strlen(command);
// imc_debug(c, 0, command); /* log incoming packets */
switch (c->state)
{
case IMC_CLOSED:
break;
case IMC_WAIT1:
clientpassword(c, command);
break;
case IMC_WAIT2:
serverpassword(c, command);
break;
case IMC_CONNECTED:
p = do_interpret_packet(c, command);
if (p)
{
#ifdef IMC_PARANOIA
/* paranoia: check the last entry in the path is the same as the
* sending mud. Also check the first entry to see that it matches
* the sender.
*/
imc_stats.rx_pkts++;
if (strcasecmp(c->info->name,
imc_lastinpath(p->i.path)))
imc_logerror("PARANOIA: packet from %s allegedly from %s",
c->info->name,
imc_lastinpath(p->i.path));
else if (strcasecmp(imc_mudof(p->i.from), imc_firstinpath(p->i.path)))
imc_logerror("PARANOIA: packet from %s has firstinpath %s",
p->i.from,
imc_firstinpath(p->i.path));
else
forward(p); /* only forward if its a valid packet! */
#else
imc_stats.rx_pkts++;
forward(p);
#endif
#ifdef SPAMPROT
if (!strcasecmp(p->type, "chat") ||
!strcasecmp(p->type, "tell") ||
!strcasecmp(p->type, "emote") || 1)
{
if (!c->spamcounter1 && !c->spamtime1)
imc_add_event(IMC_SPAM1INTERVAL, ev_spam1, c, 0);
c->spamcounter1++;
//.........这里部分代码省略.........
开发者ID:bkero,项目名称:Smaug,代码行数:101,代码来源:imc.c
示例5: clientpassword
/* handle a password from a client */
static void clientpassword(imc_connect *c, const char *argument)
{
char arg1[3], name[IMC_MNAME_LENGTH], pw[IMC_PW_LENGTH], version[20];
imc_info *i;
char response[IMC_PACKET_LENGTH];
argument=imc_getarg(argument, arg1, 4); /* packet type (has to be PW) */
argument=imc_getarg(argument, name, IMC_MNAME_LENGTH); /* remote mud name */
argument=imc_getarg(argument, pw, IMC_PW_LENGTH); /* password */
argument=imc_getarg(argument, version, 20); /* optional version=n string */
if (strcasecmp(arg1, "PW"))
{
imc_logstring("%s: non-PW password packet", imc_getconnectname(c));
do_close(c);
return;
}
/* do we know them, and do they have the right password? */
i=imc_getinfo(name);
if (!i || strcmp(i->clientpw, pw))
{
if (!i || !(i->flags & IMC_QUIET))
imc_logstring("%s: password failure for %s", imc_getconnectname(c), name);
do_close(c);
return;
}
/* deny access if deny flag is set (good for eg. muds that start crashing
* on rwho)
*/
if (i->flags & IMC_DENY)
{
if (!(i->flags & IMC_QUIET))
imc_logstring("%s: denying connection", name);
do_close(c);
return;
}
if (i->connection) /* kill old connections */
do_close(i->connection);
/* register them */
i->connection = c;
c->state = IMC_CONNECTED;
c->info = i;
c->spamcounter1 = 0;
c->spamcounter2 = 0;
/* check for a version string (assume version 0 if not present) */
if (sscanf(version, "version=%hu", &c->version)!=1)
c->version=0;
/* check for generator/interpreter */
if (!imc_vinfo[c->version].generate ||
!imc_vinfo[c->version].interpret)
{
if (!(i->flags & IMC_QUIET))
imc_logstring("%s: unsupported version %d",
imc_getconnectname(c), c->version);
do_close(c);
return;
}
/* send our response */
sprintf(response, "PW %s %s version=%d",
imc_name, i->serverpw, IMC_VERSION);
do_send(c, response);
if (!(i->flags & IMC_QUIET))
imc_logstring("%s: connected (version %d)",
imc_getconnectname(c), c->version);
c->info->timer_duration=IMC_MIN_RECONNECT_TIME;
c->info->last_connected=imc_now;
imc_cancel_event(ev_login_timeout, c);
imc_cancel_event(ev_reconnect, c->info);
}
开发者ID:bkero,项目名称:Smaug,代码行数:81,代码来源:imc.c
示例6: do_create_cmd
/********************************************************************/ /**
* Prepares and calls do_create command.
********************************************************************** */
int do_create_cmd(int args, char* argv[])
{
ARG_CHECK(args, 2);
char* filename = argv[1];
args -= 2;
argv += 2;
uint32_t max_files = FILE_DEFAULT;
uint16_t x_thumb_res = THUMB_DEFAULT;
uint16_t y_thumb_res = THUMB_DEFAULT;
uint16_t x_small_res = SMALL_DEFAULT;
uint16_t y_small_res = SMALL_DEFAULT;
// Use of int instead of size_t for the comparison with args
// For each command line argument, checks if there are enough arguments
// remaining, converts the arguments to integers and assigns them to the
// variable, and then checks if the variable is valid.
for (int i = 0; i < args; ++i) {
switch (parse_create_options(argv[i])) {
case MAX_FILES:
OPTION_ARG_CHECK(args, i, 1);
max_files = atouint32(argv[i + 1]);
if (max_files == 0 || max_files > MAX_MAX_FILES) {
return ERR_MAX_FILES;
}
i += 1;
break;
case THUMB_RES:
OPTION_ARG_CHECK(args, i, 2);
x_thumb_res = atouint16(argv[i + 1]);
y_thumb_res = atouint16(argv[i + 2]);
RES_CHECK(x_thumb_res, y_thumb_res, THUMB_MAX);
i += 2;
break;
case SMALL_RES:
OPTION_ARG_CHECK(args, i, 2);
x_small_res = atouint16(argv[i + 1]);
y_small_res = atouint16(argv[i + 2]);
RES_CHECK(x_small_res, y_small_res, SMALL_MAX);
i += 2;
break;
case INVALID_OPTION:
return ERR_INVALID_ARGUMENT;
}
}
puts("Create");
struct pictdb_header db_header = {
.max_files = max_files,
.res_resized = { x_thumb_res, y_thumb_res, x_small_res, y_small_res }
};
struct pictdb_file db_file = {.header = db_header };
int ret = do_create(filename, &db_file);
if (ret == 0) {
print_header(&db_file.header);
}
do_close(&db_file);
return ret;
}
开发者ID:vincenzobaz,项目名称:pictdb,代码行数:66,代码来源:pictDBM.c
示例7: main
//.........这里部分代码省略.........
if (script)
fatal("End of file on input\n");
else
break;
} else {
struct response resp;
lno++;
memset(&resp, 0, sizeof(resp));
rest = SkipWhite(line, REQUIRES_MORE, "Invalid line");
/* Skip totally blank line */
if (rest == NULL)
continue;
if (script && !quiet)
fprintf(stdout, "%s\n", rest);
/* If line doesn't start with a tag, that's ok */
no_tag = (!isdigit(*rest) && (*rest != '$'));
/* Parse request into response structure */
rest = parse_request(rest, &resp, no_tag);
if (rest == NULL) {
resp.r_status = STATUS_ERRNO;
resp.r_errno = errno;
} else {
/* Make sure default status is ok */
resp.r_status = STATUS_OK;
if (*rest != '\0' && *rest != '#')
fprintf_stderr(
"Command line not consumed, rest=\"%s\"\n",
rest);
switch (resp.r_cmd) {
case CMD_OPEN:
do_open(&resp);
break;
case CMD_CLOSE:
do_close(&resp);
break;
case CMD_LOCKW:
do_lock(&resp);
break;
case CMD_LOCK:
do_lock(&resp);
break;
case CMD_UNLOCK:
do_unlock(&resp);
break;
case CMD_TEST:
do_test(&resp);
break;
case CMD_LIST:
do_list(&resp);
break;
case CMD_HOP:
do_hop(&resp);
break;
case CMD_UNHOP:
do_unhop(&resp);
break;
case CMD_SEEK:
do_seek(&resp);
break;
case CMD_READ:
do_read(&resp);
break;
case CMD_WRITE:
do_write(&resp);
break;
case CMD_ALARM:
do_alarm(&resp);
break;
case CMD_HELLO:
case CMD_COMMENT:
case CMD_QUIT:
resp.r_status = STATUS_OK;
break;
case NUM_COMMANDS:
fprintf_stderr("Invalid command %s\n",
line);
continue;
}
}
respond(&resp);
if (resp.r_cmd == CMD_QUIT)
exit(0);
}
}
return 0;
}
开发者ID:asias,项目名称:nfs-ganesha,代码行数:101,代码来源:ml_posix_client.c
示例8: rtime
int
rtime (struct sockaddr_in *addrp, struct rpc_timeval *timep,
struct rpc_timeval *timeout)
{
int s;
struct pollfd fd;
int milliseconds;
int res;
/* RFC 868 says the time is transmitted as a 32-bit value. */
uint32_t thetime;
struct sockaddr_in from;
int fromlen;
int type;
if (timeout == NULL)
type = SOCK_STREAM;
else
type = SOCK_DGRAM;
s = __socket (AF_INET, type, 0);
if (s < 0)
return (-1);
addrp->sin_family = AF_INET;
addrp->sin_port = htons (IPPORT_TIMESERVER);
if (type == SOCK_DGRAM)
{
res = __sendto (s, (char *) &thetime, sizeof (thetime), 0,
(struct sockaddr *) addrp, sizeof (*addrp));
if (res < 0)
{
do_close (s);
return -1;
}
milliseconds = (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000);
fd.fd = s;
fd.events = POLLIN;
do
res = __poll (&fd, 1, milliseconds);
while (res < 0 && errno == EINTR);
if (res <= 0)
{
if (res == 0)
__set_errno (ETIMEDOUT);
do_close (s);
return (-1);
}
fromlen = sizeof (from);
res = __recvfrom (s, (char *) &thetime, sizeof (thetime), 0,
(struct sockaddr *) &from, &fromlen);
do_close (s);
if (res < 0)
return -1;
}
else
{
if (__connect (s, (struct sockaddr *) addrp, sizeof (*addrp)) < 0)
{
do_close (s);
return -1;
}
res = __read (s, (char *) &thetime, sizeof (thetime));
do_close (s);
if (res < 0)
return (-1);
}
if (res != sizeof (thetime))
{
__set_errno (EIO);
return -1;
}
thetime = ntohl (thetime);
timep->tv_sec = thetime - TOFFSET;
timep->tv_usec = 0;
return 0;
}
开发者ID:mbref,项目名称:glibc-236-microblaze,代码行数:76,代码来源:rtime.c
示例9: close_socket
static void close_socket(MVMThreadContext *tc, MVMOSHandle *h) {
MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)h->body.data;
do_close(tc, data);
}
开发者ID:grondilu,项目名称:MoarVM,代码行数:4,代码来源:syncsocket.c
示例10: connect_vcc
int connect_vcc(struct sockaddr *remote,const struct atm_qos *qos,int sndbuf,
int timeout)
{
int fd,error,flags;
if (remote->sa_family == AF_ATMSVC && incoming < 0) return -EUNATCH;
if ((fd = socket(remote->sa_family,SOCK_DGRAM,0)) < 0) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"socket: %s",strerror(errno));
return error;
}
if (setsockopt(fd,SOL_ATM,SO_ATMQOS,qos,sizeof(*qos)) < 0) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"setsockopt SO_ATMQOS: %s",strerror(errno));
return error;
}
if (sndbuf)
if (setsockopt(fd,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"setsockopt SO_SNDBUF: %s",
strerror(errno));
return error;
}
if ((flags = fcntl(fd,F_GETFL)) < 0) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"fcntl F_GETFL: %s",strerror(errno));
return error;
}
flags |= O_NONBLOCK;
if (fcntl(fd,F_SETFL,flags) < 0) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"fcntl F_GETFL: %s",strerror(errno));
return error;
}
if (remote->sa_family == AF_ATMSVC) { /* @@@ that's cheating */
struct atm_sap sap;
memset(&sap,0,sizeof(sap));
sap.blli[0].l2_proto = ATM_L2_ISO8802;
sap.blli[0].l3_proto = ATM_L3_NONE;
if (setsockopt(fd,SOL_ATM,SO_ATMSAP,&sap,sizeof(sap)) < 0) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"setsockopt SO_ATMSAP: %s",
strerror(errno));
return error;
}
}
/* PVC connect never blocks */
if (connect(fd,remote,remote->sa_family == AF_ATMPVC ?
sizeof(struct sockaddr_atmpvc) : sizeof(struct sockaddr_atmsvc)) < 0) {
if (errno != EINPROGRESS) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"[1]connect: %s",strerror(errno));
return error;
}
return fd;
}
if (ioctl(fd,ATMARP_MKIP,timeout) < 0) {
error = -errno;
diag(COMPONENT,DIAG_ERROR,"ioctl ATMARP_MKIP: %s",strerror(errno));
(void) do_close(fd);
return error;
}
return fd;
}
开发者ID:ebichu,项目名称:dd-wrt,代码行数:65,代码来源:io.c
示例11: parse_admin
// 0x7944 - request account id lookup by name (response: 0x7945)
// 0x7946 - request account name lookup by id (response: 0x7947)
// 0x7952 - request account information lookup by name (response: 0x7953)
// 0x7954 - request account information lookup by id (response: 0x7953)
//---------------------------------------
int parse_admin(int fd)
{
unsigned int i, j;
char* account_name;
struct mmo_account acc;
uint32 ipl = session[fd]->client_addr;
char ip[16];
ip2str(ipl, ip);
if( session[fd]->flag.eof )
{
do_close(fd);
ShowInfo("Remote administration has disconnected (session #%d).\n", fd);
return 0;
}
while( RFIFOREST(fd) >= 2 )
{
uint16 command = RFIFOW(fd,0);
switch( command )
{
case 0x7530: // Request of the server version
ShowStatus("'ladmin': Sending of the server version (ip: %s)\n", ip);
WFIFOHEAD(fd,10);
WFIFOW(fd,0) = 0x7531;
WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
WFIFOB(fd,4) = ATHENA_REVISION;
WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
WFIFOB(fd,7) = ATHENA_SERVER_LOGIN;
WFIFOW(fd,8) = ATHENA_MOD_VERSION;
WFIFOSET(fd,10);
RFIFOSKIP(fd,2);
break;
/*
case 0x7920: // Request of an accounts list
if (RFIFOREST(fd) < 10)
return 0;
{
int st, ed;
uint16 len;
CREATE_BUFFER(id, int, auth_num);
st = RFIFOL(fd,2);
ed = RFIFOL(fd,6);
RFIFOSKIP(fd,10);
WFIFOW(fd,0) = 0x7921;
if (st < 0)
st = 0;
if (ed > END_ACCOUNT_NUM || ed < st || ed <= 0)
ed = END_ACCOUNT_NUM;
ShowStatus("'ladmin': Sending an accounts list (ask: from %d to %d, ip: %s)\n", st, ed, ip);
// Sort before send
for(i = 0; i < auth_num; i++) {
unsigned int k;
id[i] = i;
for(j = 0; j < i; j++) {
if (auth_dat[id[i]].account_id < auth_dat[id[j]].account_id) {
for(k = i; k > j; k--) {
id[k] = id[k-1];
}
id[j] = i; // id[i]
break;
}
}
}
// Sending accounts information
len = 4;
for(i = 0; i < auth_num && len < 30000; i++) {
int account_id = auth_dat[id[i]].account_id; // use sorted index
if (account_id >= st && account_id <= ed) {
j = id[i];
WFIFOL(fd,len) = account_id;
WFIFOB(fd,len+4) = (unsigned char)isGM(account_id);
memcpy(WFIFOP(fd,len+5), auth_dat[j].userid, 24);
WFIFOB(fd,len+29) = auth_dat[j].sex;
WFIFOL(fd,len+30) = auth_dat[j].logincount;
if (auth_dat[j].state == 0 && auth_dat[j].unban_time != 0) // if no state and banished
WFIFOL(fd,len+34) = 7; // 6 = Your are Prohibited to log in until %s
else
WFIFOL(fd,len+34) = auth_dat[j].state;
len += 38;
}
}
WFIFOW(fd,2) = len;
WFIFOSET(fd,len);
//if (id) free(id);
DELETE_BUFFER(id);
}
break;
*/
case 0x7930: // Request for an account creation
//.........这里部分代码省略.........
开发者ID:milky-milk,项目名称:ro-server-repos,代码行数:101,代码来源:admin.c
示例12: accept_new
static void accept_new(void)
{
char buffer[MAX_ATM_ADDR_LEN+1];
struct sockaddr_atmsvc addr;
struct atm_qos qos;
ENTRY *entry;
VCC *vcc;
int fd,error;
socklen_t len,size;
len = sizeof(addr);
if ((fd = accept(incoming,(struct sockaddr *) &addr,&len)) < 0) {
error = errno;
diag(COMPONENT,DIAG_ERROR,"accept: %s",strerror(errno));
if (error == EUNATCH) {
diag(COMPONENT,DIAG_WARN,"disabling SVCs");
(void) close(incoming);
incoming = -1;
}
return;
}
/* the following code probably belongs to arp.c ... */
if (atm2text(buffer,MAX_ATM_ADDR_LEN+1,(struct sockaddr *) &addr,pretty) <
0) strcpy(buffer,"<atm2text error>");
diag(COMPONENT,DIAG_DEBUG,"Incoming call from %s",buffer);
size = sizeof(qos);
if (getsockopt(fd,SOL_ATM,SO_ATMQOS,&qos,&size) < 0)
diag(COMPONENT,DIAG_FATAL,"getsockopt SO_ATMQOS: %s",strerror(errno));
if (size != sizeof(qos))
diag(COMPONENT,DIAG_FATAL,"SO_ATMQOS: size %d != %d",size,sizeof(qos));
if (ioctl(fd,ATMARP_MKIP,qos.txtp.traffic_class == ATM_NONE ? 0 :
CLIP_DEFAULT_IDLETIMER) < 0) {
diag(COMPONENT,DIAG_ERROR,"ioctl ATMARP_MKIP: %s",strerror(errno));
(void) do_close(fd);
return;
}
vcc = alloc_t(VCC);
vcc->active = 0;
vcc->connecting = 0;
vcc->fd = fd;
if (qos.txtp.traffic_class == ATM_NONE) {
vcc->entry = NULL;
incoming_unidirectional(vcc);
Q_INSERT_HEAD(unidirectional_vccs,vcc);
return;
}
if (merge) {
ITF *itf;
for (itf = itfs; itf; itf = itf->next) {
entry = lookup_addr(itf,&addr);
if (entry) {
vcc->entry = entry;
Q_INSERT_HEAD(entry->vccs,vcc);
if (entry->state == as_valid) {
if (set_ip(vcc->fd,entry->ip) < 0) {
diag(COMPONENT,DIAG_ERROR,"set_ip: %s",
strerror(errno));
disconnect_vcc(vcc);
}
else set_sndbuf(vcc);
}
return;
}
}
}
entry = alloc_entry(1);
entry->state = as_invalid;
entry->addr = alloc_t(struct sockaddr_atmsvc);
*entry->addr = addr;
entry->flags = ATF_PUBL;
Q_INSERT_HEAD(unknown_incoming,entry);
vcc->entry = entry;
Q_INSERT_HEAD(entry->vccs,vcc);
incoming_call(vcc);
}
开发者ID:ebichu,项目名称:dd-wrt,代码行数:76,代码来源:io.c
示例13: task_fs
/**
* <Ring 1> The main loop of TASK FS.
*
*****************************************************************************/
PUBLIC void task_fs()
{
printl("{FS} Task FS begins.\n");
init_fs();
while (1) {
send_recv(RECEIVE, ANY, &fs_msg);
int msgtype = fs_msg.type;
int src = fs_msg.source;
pcaller = &proc_table[src];
switch (msgtype) {
case OPEN:
fs_msg.FD = do_open();
break;
case CLOSE:
fs_msg.RETVAL = do_close();
break;
case READ:
case WRITE:
fs_msg.CNT = do_rdwt();
break;
case UNLINK:
fs_msg.RETVAL = do_unlink();
break;
case RESUME_PROC:
src = fs_msg.PROC_NR;
break;
case FORK:
fs_msg.RETVAL = fs_fork();
break;
case EXIT:
fs_msg.RETVAL = fs_exit();
break;
case LSEEK:
fs_msg.OFFSET = do_lseek();
break;
case STAT:
fs_msg.RETVAL = do_stat();
break;
default:
dump_msg("FS::unknown message:", &fs_msg);
assert(0);
break;
}
#ifdef ENABLE_DISK_LOG
char * msg_name[128];
msg_name[OPEN] = "OPEN";
msg_name[CLOSE] = "CLOSE";
msg_name[READ] = "READ";
msg_name[WRITE] = "WRITE";
msg_name[LSEEK] = "LSEEK";
msg_name[UNLINK] = "UNLINK";
msg_name[FORK] = "FORK";
msg_name[EXIT] = "EXIT";
msg_name[STAT] = "STAT";
switch (msgtype) {
case UNLINK:
dump_fd_graph("%s just finished. (pid:%d)",
msg_name[msgtype], src);
//panic("");
case OPEN:
case CLOSE:
case READ:
case WRITE:
case FORK:
case EXIT:
case LSEEK:
case STAT:
break;
case RESUME_PROC:
break;
default:
assert(0);
}
#endif
/* reply */
if (fs_msg.type != SUSPEND_PROC) {
fs_msg.type = SYSCALL_RET;
send_recv(SEND, src, &fs_msg);
}
}
}
开发者ID:Anuriel,项目名称:Orange-System,代码行数:92,代码来源:main.c
示例14: connect_client
static int connect_client(int listen_fd)
{
int fd;
struct sockaddr_in client_address;
#ifdef __WIN32
int len;
#else
socklen_t len;
#endif
//ShowMessage("connect_client : %d\n",listen_fd);
len=sizeof(client_address);
fd = accept(listen_fd,(struct sockaddr*)&client_address,&len);
#ifdef __WIN32
if (fd == SOCKET_ERROR || fd == INVALID_SOCKET || fd < 0) {
ShowError("accept failed (code %d)!\n", fd, WSAGetLastError());
return -1;
}
#else
if(fd==-1) {
perror("accept");
return -1;
}
#endif
if(fd_max<=fd) fd_max=fd+1;
setsocketopts(fd);
#ifdef __WIN32
{
unsigned long val = 1;
if (ioctlsocket(fd, FIONBIO, &val) != 0)
ShowError("Nao e necessario ajustar o soquete � modalidade non-blocking (code %d)!\n", WSAGetLastError());
}
#else
if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1)
perror("connect_client (set nonblock)");
#endif
if (ip_rules && !connect_check(*(unsigned int*)(&client_address.sin_addr))) {
do_close(fd);
return -1;
} else
FD_SET(fd,&readfds);
CREATE(session[fd], struct socket_data, 1);
CREATE_A(session[fd]->rdata, unsigned char, rfifo_size);
CREATE_A(session[fd]->wdata, unsigned char, wfifo_size);
session[fd]->max_rdata = (int)rfifo_size;
session[fd]->max_wdata = (int)wfifo_size;
session[fd]->func_recv = recv_to_fifo;
session[fd]->func_send = send_from_fifo;
session[fd]->func_parse = default_func_parse;
session[fd]->client_addr = client_address;
session[fd]->rdata_tick = last_tick;
session[fd]->type = SESSION_UNKNOWN; // undefined type
//ShowMessage("new_session : %d %d\n",fd,session[fd]->eof);
return fd;
}
开发者ID:AxlSckay,项目名称:Ragnarok-OldTimes,代码行数:63,代码来源:socket.c
示例15: do_read
static int
do_read(struct client* c, struct client_info* info) {
assert(info->connect_type == SOCKET_CONNECTED);
int to_id = info->to_id;
if (to_id < 0) {
to_id = connect_to(c, info->id);
if (to_id == -1) {
do_close(c, info);
return -1;
}
info->to_id = to_id;
c->free_connection -= 1;
c->time = 0;
}
int len;
struct client_info* to_info = &c->all_fds[to_id % TOTAL_CONNECTION];
if (to_info->id != to_id) {
do_close(c, info);
return -1;
}
char* buffer = get_ring_buffer_write_ptr(to_info->buffer, &len);
if (!buffer) {
return 0; //buff fulled
}
int n = (int)read(info->fd, buffer, len);
if (n == -1) {
switch (errno) {
case EAGAIN:
fprintf(stderr, "%s read fd error:EAGAIN.\n", get_time());
break;
case EINTR:
break;
default:
fprintf(stderr, "%s client: read (id=%d) error :%s. \n", get_time(), info->id, strerror(errno));
do_close(c, info);
return -1;
}
return 1;
}
if (n == 0) {
do_close(c, info); //normal close
return -1;
}
move_ring_buffer_write_pos(to_info->buffer, n);
FD_SET(to_info->fd, &c->fd_wset);
if (n == len && !is_ring_buffer_empty(to_info->buffer)) {
fprintf(stderr, "%s client: read again.\n", get_time());
return do_read(c, info);
}
return 1;
}
开发者ID:fu122zh,项目名称:tunnel,代码行数:62,代码来源:client.c
示例16: gc_free
static void gc_free(MVMThreadContext *tc, MVMObject *h, void *d) {
MVMIOSyncSocketData *data = (MVMIOSyncSocketData *)d;
do_close(tc, data);
}
开发者ID:grondilu,项目名称:MoarVM,代码行数:4,代码来源:syncsocket.c
示例17: client_thread
static void*
client_thread(void* param) {
struct client_param* cp = (struct client_param*)param;
struct client c;
memset(&c, 0, sizeof(c));
sprintf(c.remote_ip, "%s", cp->remote_ip);
c.remote_port = cp->p1;
c.ssh_port = cp->p2;
c.wait_closed = alloc_ring_buffer(sizeof(int) * TOTAL_CONNECTION);
FD_ZERO(&c.fd_rset);
FD_ZERO(&c.fd_wset);
FD_SET(cp->pid, &c.fd_rset);
c.max_fd = cp->pid + 1;
sp_nonblocking(cp->pid);
while (1) {
pre_check_close(&c);
if (connect_to(&c, -1) == -1 && c.cnt == 0) {
c.max_fd = cp->pid + 1;
int buff = 0;
int n = (int)read(cp->pid, &buff, sizeof(int));
if (n > 0) {
break;
}
sleep(1);
continue;
}
fd_set r_set = c.fd_rset;
fd_set w_set = c.fd_wset;
int cnt = select(c.max_fd, &r_set, &w_set, NULL, NULL);
if (cnt == -1) {
fprintf(stderr, "%s select error: %s.\n", get_time(), strerror(errno));
continue;
}
int i;
for (i = c.cnt - 1; i >= 0 && cnt > 0; --i) {
int id = c.all_ids[i] % TOTAL_CONNECTION;
struct client_info* info = &c.all_fds[id];
assert(c.all_ids[i] == info->id);
int fd = info->fd;
assert(fd > 0);
if (FD_ISSET(fd, &r_set)) {
// read
--cnt;
if (do_read(&c, info) == -1) continue;
}
if (FD_ISSET(fd, &w_set)) {
//write
--cnt;
if (do_write(&c, info, 0) == -1) continue;
}
}
if (FD_ISSET(cp->pid, &r_set)) {
//exit
break;
}
}
fprintf(stderr, "%s ====================CLIENT: SEND LAST DATA BEGIN===================.\n", get_time());
int i;
for (i = c.cnt - 1; i >= 0; --i) {
int id = c.all_ids[i] % TOTAL_CONNECTION;
struct client_info* info = &c.all_fds[id];
assert(c.all_ids[i] == info->id);
if (do_write(&c, info, 1) != -1) {
do_close(&c, info);
}
}
fprintf(stderr, "%s ====================CLIENT: SEND LAST DATA END=====================.\n", get_time());
free_ring_buffer(c.wait_closed);
assert(c.cnt == 0);
return NULL;
}
开发者ID:fu122zh,项目名称:tunnel,代码行数:90,代码来源:client.c
示例18: on_req
static int on_req(h2o_handler_t *_self, h2o_req_t *req)
{
h2o_file_handler_t *self = (void*)_self;
h2o_buf_t vpath, mime_type;
char *rpath;
size_t rpath_len;
struct st_h2o_sendfile_generator_t *generator = NULL;
size_t if_modified_since_header_index, if_none_match_header_index;
int is_dir;
/* only accept GET (TODO accept HEAD as well) */
if (! h2o_memis(req->method.base, req->method.len, H2O_STRLIT("GET")))
return -1;
/* prefix match */
if (req->path.len < self->virtual_path.len
|| memcmp(req->path.base, self->virtual_path.base, self->virtual_path.len) != 0)
return -1;
/* normalize path */
vpath = h2o_normalize_path(&req->pool, req->path.base + self->virtual_path.len - 1, req->path.len - self->virtual_path.len + 1);
if (vpath.len > PATH_MAX)
return -1;
/* build path (still unterminated at the end of the block) */
rpath = alloca(
self->real_path.len
+ (vpath.len - 1) /* exclude "/" at the head */
+ self->max_index_file_len
+ 1);
rpath_len = 0;
memcpy(rpath + rpath_len, self->real_path.base, self->real_path.len);
rpath_len += self->real_path.len;
memcpy(rpath + rpath_len, vpath.base + 1, vpath.len - 1);
rpath_len += vpath.len - 1;
/* build generator (as well as terminating the rpath and its length upon success) */
if (rpath[rpath_len - 1] == '/') {
h2o_buf_t *index_file;
for (index_file = self->index_files; index_file->base != NULL; ++index_file) {
memcpy(rpath + rpath_len, index_file->base, index_file->len);
rpath[rpath_len + index_file->len] = '\0';
if ((generator = create_generator(&req->pool, rpath, &is_dir)) != NULL) {
rpath_len += index_file->len;
break;
}
if (is_dir) {
/* note: apache redirects "path/" to "path/index.txt/" if index.txt is a dir */
char *path = alloca(req->path.len + index_file->len + 1);
size_t path_len = sprintf(path, "%.*s%.*s", (int)req->path.len, req->path.base, (int)index_file->len, index_file->base);
return redirect_to_dir(req, path, path_len);
}
if (errno != ENOENT)
break;
}
} else {
rpath[rpath_len] = '\0';
generator = create_generator(&req->pool, rpath, &is_dir);
if (generator == NULL && is_dir)
return redirect_to_dir(req, req->path.base, req->path.len);
}
/* return error if failed */
if (generator == NULL) {
if (errno == ENOENT) {
h2o_send_error(req, 404, "File Not Found", "file not found");
} else {
h2o_send_error(req, 403, "Access Forbidden", "access forbidden");
}
return 0;
}
if ((if_none_match_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_NONE_MATCH, SIZE_MAX)) != -1) {
h2o_buf_t *if_none_match = &req->headers.entries[if_none_match_header_index].value;
if (h2o_memis(if_none_match->base, if_none_match->len, generator->etag_buf, generator->etag_len))
goto NotModified;
} else if ((if_modified_since_header_index = h2o_find_header(&req->headers, H2O_TOKEN_IF_MODIFIED_SINCE, SIZE_MAX)) != -1) {
h2o_buf_t *if_modified_since = &req->headers.entries[if_modified_since_header_index].value;
if (h2o_memis(if_modified_since->base, if_modified_since->len, generator->last_modified_buf, H2O_TIMESTR_RFC1123_LEN))
goto NotModified;
}
/* obtain mime type */
mime_type = h2o_mimemap_get_type(self->mimemap, h2o_get_filext(rpath, rpath_len));
/* return file */
do_send_file(generator, req, 200, "OK", mime_type);
return 0;
NotModified:
req->res.status = 304;
req->res.reason = "Not Modified";
h2o_send_inline(req, NULL, 0);
do_close(&generator->super, req);
return 0;
}
开发者ID:lhjay1,项目名称:h2o,代码行数:95,代码来源:file.c
|
请发表评论