本文整理汇总了C++中send_file函数的典型用法代码示例。如果您正苦于以下问题:C++ send_file函数的具体用法?C++ send_file怎么用?C++ send_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sys_sendfile
ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count)
{
size_t total=0;
struct sf_parms hdtrl;
/* Set up the header/trailer struct params. */
if (header) {
hdtrl.header_data = header->data;
hdtrl.header_length = header->length;
} else {
hdtrl.header_data = NULL;
hdtrl.header_length = 0;
}
hdtrl.trailer_data = NULL;
hdtrl.trailer_length = 0;
hdtrl.file_descriptor = fromfd;
hdtrl.file_offset = offset;
hdtrl.file_bytes = count;
while ( hdtrl.file_bytes + hdtrl.header_length ) {
ssize_t ret;
/*
Return Value
There are three possible return values from send_file:
Value Description
-1 an error has occurred, errno contains the error code.
0 the command has completed successfully.
1 the command was completed partially, some data has been
transmitted but the command has to return for some reason,
for example, the command was interrupted by signals.
*/
do {
ret = send_file(&tofd, &hdtrl, 0);
} while ( (ret == 1) || (ret == -1 && errno == EINTR) );
if ( ret == -1 )
return -1;
}
return count + header->length;
}
示例2: respond
/*
* will be called for each file
* no return -- errors will be sent by subsequent functions
*/
int respond(const int fd, const char* file) {
resp_hdrs hdrs;
init_resp_headers(&hdrs);
int file_fd;
off_t file_size;
if (file == NULL) {
fprintf(stderr, "file not specified\n");
hdrs.status_code = 404;
}
else {
file_fd = f_open(file);
if (file_fd == -1) {
fprintf(stderr, "file not found\n");
hdrs.status_code = 404;
} else {
hdrs.status_code = 200;
}
file_size = f_size(file_fd);
if (file_size == -1) {
fprintf(stderr, "file size error\n");
hdrs.status_code = 404;
}
}
if (file != NULL) {
hdrs.content_length = file_size;
hdrs.last_modified = f_last_mod(file_fd);
send_headers(fd, &hdrs);
}
if (hdrs.status_code != 404) {
send_file(fd, file_fd, file_size);
} else {
char* msg404 =
"<html><head><title>404 Not Found</head></title><body><p>404 Not "
"Found: The requested resource could not be found!</p></body></html>";
send_msg(fd, msg404);
}
return 0;
}
示例3: while
void *child_thread(void* pf)
{
pfact p = (pfact)pf;
int rfd;
while(1)
{
pthread_mutex_lock(&p->que.mutex);
if(p->que.size == 0)
{
pthread_cond_wait(&p->cond,&p->que.mutex);
}
que_deque(&p->que,&rfd);
pthread_mutex_unlock(&p->que.mutex);
send_file(rfd);
printf("%d send successful!\n",rfd);
}
}
示例4: send_errorpage
/* Generates and sends an error document */
void send_errorpage(request *r) {
char *page = NULL;
size_t len = 0;
int fildes;
char file[decimal_length(int) + 5 + 1];/* an int, .html, \0 */
/* Look for a ready-made error document */
snprintf(file, 9, "%d.html", r->status);
if((fildes = open(file, O_RDONLY)) != -1) {/* file exists and is readable */
close(fildes);
/* set up the request structure */
free(r->file);
r->file = strdup(file);
file_stuff(r);
send_file(r);
return;
}
/* Generate page */
add_text(&page, &len, "<html><head><title>%d %s</title></head>\n", r->status,
status_reason[r->status]);
add_text(&page, &len, "<body><h1>%d %s</h1>\n", r->status,
status_reason[r->status]);
if(page_text[r->status])
add_text(&page, &len, page_text[r->status]);
else
add_text(&page, &len, "See "
"<a href=\"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\">"
"this</a> for more information.");
add_text(&page, &len, "\n</body></html>\n");
/* And now send the page */
free(r->content_type);
r->content_type = strdup("text/html");
r->encoding = IDENTITY;
r->content_length = len;
send_headers(r);
send_str(r->fd, "\r\n");
if(r->meth != HEAD) send(r->fd, page, len, 0);
free(page);
}
示例5: send_func
void* send_func(void*p)
{
int fd = (int)p;
int end = 0xffffffff;
int i;
pthread_t id = pthread_self();
printf("ready send %d\n", (int)id);
for(i=0; i<max_files; i++)
{
send_file(fd, files[i]);
}
send(fd, &end, sizeof(end), 0);
printf("end send %d\n", (int)id);
close(fd);
}
示例6: go_cmd
/** send command and display result */
static int
go_cmd(SSL* ssl, int quiet, int argc, char* argv[])
{
char pre[10];
const char* space=" ";
const char* newline="\n";
int was_error = 0, first_line = 1;
int r, i;
char buf[1024];
snprintf(pre, sizeof(pre), "UBCT%d ", UNBOUND_CONTROL_VERSION);
if(SSL_write(ssl, pre, (int)strlen(pre)) <= 0)
ssl_err("could not SSL_write");
for(i=0; i<argc; i++) {
if(SSL_write(ssl, space, (int)strlen(space)) <= 0)
ssl_err("could not SSL_write");
if(SSL_write(ssl, argv[i], (int)strlen(argv[i])) <= 0)
ssl_err("could not SSL_write");
}
if(SSL_write(ssl, newline, (int)strlen(newline)) <= 0)
ssl_err("could not SSL_write");
if(argc == 1 && strcmp(argv[0], "load_cache") == 0) {
send_file(ssl, stdin, buf, sizeof(buf));
}
while(1) {
ERR_clear_error();
if((r = SSL_read(ssl, buf, (int)sizeof(buf)-1)) <= 0) {
if(SSL_get_error(ssl, r) == SSL_ERROR_ZERO_RETURN) {
/* EOF */
break;
}
ssl_err("could not SSL_read");
}
buf[r] = 0;
if(first_line && strncmp(buf, "error", 5) == 0) {
printf("%s", buf);
was_error = 1;
} else if (!quiet)
printf("%s", buf);
first_line = 0;
}
return was_error;
}
示例7: found_regular_file
static int found_regular_file(struct asfd *asfd,
FF_PKT *ff_pkt, struct conf *conf,
char *fname, bool top_level)
{
boffset_t sizeleft;
sizeleft=ff_pkt->statp.st_size;
// If the user specified a minimum or maximum file size, obey it.
if(conf->min_file_size && sizeleft<(boffset_t)conf->min_file_size)
return 0;
if(conf->max_file_size && sizeleft>(boffset_t)conf->max_file_size)
return 0;
ff_pkt->type=FT_REG;
return send_file(asfd, ff_pkt, top_level, conf);
}
示例8: handle_request
void* handle_request(void* arg)
{
pfactory_t pf=(pfactory_t)arg;
pque_t pq=&pf->s_que;
pnode_t pget;
while(1)
{
pthread_mutex_lock(&pq->q_mutex);
if(pq->size == 0)
{
pthread_cond_wait(&pf->cond,&pq->q_mutex);
}
que_get(pq,&pget);
pthread_mutex_unlock(&pq->q_mutex);
send_file(pget->sockfd);
free(pget);
}
}
示例9: port_handler
int port_handler(int work_sockfd, int listenfd, int port, char* fileName, int retr_stor) {
int connfd;
char buffer[8192];
int recv_len, write_len;
FILE *fp;
if (retr_stor == 0) {
char *tmp_str = waiting_for(work_sockfd, "");
char num[256];
strcpy(num, split(tmp_str, " ", 2)[0]);
if (strcmp(num, "150") != 0) {
close(listenfd);
return 1;
}
}
if ((connfd = accept(listenfd, NULL, NULL)) == -1) {
printf("Error accept(): %s(%d)\n", strerror(errno), errno);
waiting_for(work_sockfd, "");
close(listenfd);
return 1;
}
if (retr_stor == 0) {
if (recv_file(work_sockfd, connfd, fileName) == 1) {
close(connfd);
close(listenfd);
return 1;
}
} else {
if (send_file(work_sockfd, connfd, fileName) == 1) {
close(connfd);
close(listenfd);
return 1;
}
}
close(connfd);
close(listenfd);
return STATUS_OK;
}
示例10: thread_handle
void* thread_handle(void* arg)//子线程函数流程,先初始化,再启动,一般这两个是分开的
{
while(1)//让每个线程可以启动
{
pfactory pf=(pfactory)arg;
printf("the start_flag is %d\n",pf->start_flag);
pque_t pq=&pf->fd_que;
pnode pcur;//因为中间没有对pcur进行判断,所以不用先初始化为null
if(factory_que_empty(pq))//子线程判断队列是否为空,如果为空,则不去get。为空返回1,不为空返回0
{
pthread_cond_wait(&pf->cond,&pq->mutex);//wait之前得先加锁,wait时解锁,wait后又加锁,
//为空等待对应的条件变量
pthread_mutex_unlock(&pq->mutex);
}
factory_que_get(pq,&pcur);//等待结束又可以get
send_file(pcur->new_fd);//将描述符发过去就可以向客户端发文件了
free(pcur);//发过去之后将链表中该节点free掉,因为空间是在主线程中申请的,所以要在主线程中free
}
}
示例11: main
int main(int argc, char *argv[])
{
char *pname;
char *host;
char *port;
char *AEtitle;
char **file_list;
int ifile, num_files;
Acr_File *afpin, *afpout;
/* Check arguments */
pname = argv[0];
if (argc < 5) {
(void) fprintf(stderr, "Usage: %s host port AEtitle files ...\n", pname);
return EXIT_FAILURE;
}
host = argv[1];
port = argv[2];
AEtitle = argv[3];
file_list = &argv[4];
num_files = argc - 4;
/* Make dicom connection */
if (!acr_open_dicom_connection(host, port, AEtitle, "test",
ACR_MR_IMAGE_STORAGE_UID,
ACR_IMPLICIT_VR_LITTLE_END_UID,
&afpin, &afpout)) {
return EXIT_FAILURE;
}
/* Loop over the input files, sending them one at a time */
for (ifile = 0; ifile < num_files; ifile++) {
(void) printf("Sending file %s\n", file_list[ifile]);
if (!send_file(afpin, afpout, file_list[ifile])) {
break;
}
}
/* Release the association */
acr_close_dicom_connection(afpin, afpout);
return EXIT_SUCCESS;
}
示例12: do_send_file
static errval_t do_send_file(struct in_addr *addr, int port, char *path)
{
assert(addr != NULL);
assert(path != NULL);
errval_t err;
debug_printf("send file %s to %s:%d\n", path, inet_ntoa(*addr), port);
static struct ip_addr ip;
ip.addr = addr->s_addr; // XXX
// debug_printf("ready to connect\n");
struct tcp_pcb *pcb;
pcb = connect(&ip, port);
if (pcb == NULL) {
assert(pcb != NULL);
// return SOME_ERR;
}
// debug_printf("connected\n");
// debug_printf("start sending.\n");
wait_cond = true;
err = send_file(pcb, path);
if (err_is_fail(err)) {
return err;
}
wait_for_condition();
debug_printf("send finished.\n");
// debug_printf("closing connection.\n");
// close_connection(pcb);
debug_printf("connection closed.\n");
return SYS_ERR_OK;
}
示例13: file_mode
int file_mode(){
printf("[file_mode]> ");
memset(inputbuf, 0, INPUT_BUFSIZE);
setbuf(stdin, NULL);
fgets(inputbuf, INPUT_BUFSIZE, stdin);
setbuf(stdin, NULL);
char *friend_name;
char *trans_location;
friend_name = strtok(inputbuf, ":");
trans_location = strtok(NULL, "\n");
if (friend_name != NULL && trans_location != NULL) {
send_file(friend_name, trans_location);
return TRUE;
}
printf("%s", "file mode usage\t<$name><:><$location>\n");
return FALSE;
}
示例14: my_put
void my_put(int sock, char buff[1024], char *path)
{
char **args;
int i;
i = 0;
args = totab(buff, ' ');
if (getSize(args) == 2)
{
while (args[1][i] != '\0')
{
if (args[1][i] == '\n')
args[1][i] = '\0';
i++;
}
send_file(sock, buff, args[1], path);
}
else
send_error(sock, "Usage : get <file>");
}
示例15: my_get
int my_get(t_cli **cli)
{
char **args;
int i;
i = 0;
args = totab((*cli)->buff, ' ');
if (getSize(args) == 2)
{
while (args[1][i] != '\0')
{
if (args[1][i] == '\n')
args[1][i] = '\0';
i++;
}
return (send_file(cli, args[1]));
}
else
return (send_error((*cli)->cs, "Usage : get <file>"));
}