• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ send_header函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中send_header函数的典型用法代码示例。如果您正苦于以下问题:C++ send_header函数的具体用法?C++ send_header怎么用?C++ send_header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了send_header函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: send_data

void send_data(int send_to, char *content_type, char *filepath)
{
    if (strcmp(filepath, "./") == 0)
    {
        strcat(filepath, DEFAULT_INDEX_PAGE);
    }
    FILE *file;
    file = fopen(filepath, "r");
    if (file != NULL)
    {
        send_header(send_to, content_type);
        send(send_to, "\r\n", 2, 0);

        char buf[1024];

        fgets(buf, sizeof(buf), file);
        while (!feof(file))
        {
            send(send_to, buf, strlen(buf), 0);
            fgets(buf, sizeof(buf), file);
        }

    } else
    {
        send_header(send_to, content_type);
        send(send_to, "\r\n", 2, 0);
        not_found_404(send_to);
    }
    if (file != NULL)
        fclose(file);

}
开发者ID:lfzark,项目名称:KServer,代码行数:32,代码来源:kserver.c


示例2: show_welcome

void show_welcome(Serial *serial){
	put_crlf(serial);
	size_t len = strlen(welcomeMsg);
	send_header(serial, len);
	serial->put_s(welcomeMsg);
	put_crlf(serial);
	send_header(serial, len);
	put_crlf(serial);
	show_help(serial);
}
开发者ID:jrwiebe,项目名称:RaceCapture-Pro_firmware,代码行数:10,代码来源:command.c


示例3: send_response

//request message referred from textbook page 105-106
void send_response(int socket, char *file_name)
{
    //if file name is empty, return
    if (*file_name == '\0')
    {
        send_header(socket, file_name, 0, code_404);
        send(socket, ERROR_404_MESSAGE, strlen(ERROR_404_MESSAGE), 0);
        return;
    }

    FILE *fp = fopen(file_name, "r");

    //if file not found, return
    if (!fp)
    {
        send_header(socket, file_name, 0, code_404);
        send(socket, ERROR_404_MESSAGE, strlen(ERROR_404_MESSAGE), 0);
        return;
    }

    if (!fseek(fp, 0, SEEK_END))
    {
        long file_len = ftell(fp);

        //if file length error, return
        if (file_len < 0)
        {
            send_header(socket, file_name, 0, code_404);
            send(socket, ERROR_404_MESSAGE, strlen(ERROR_404_MESSAGE), 0);
            return;
        }

        char *file_buffer = malloc(sizeof(char) * (file_len + 1));
        fseek(fp, 0, SEEK_SET);

        size_t num_bytes = fread(file_buffer, sizeof(char), file_len, fp);
        file_buffer[num_bytes] = '\0';

        send_header(socket, file_name, num_bytes, code_200);

        //send file to socket
        send(socket, file_buffer, num_bytes, 0);

        free(file_buffer);
    }

    fclose(fp);
}
开发者ID:Sarabostani,项目名称:UCLA-CS118,代码行数:49,代码来源:webserver.c


示例4: sanlock_request

int sanlock_request(uint32_t flags, uint32_t force_mode,
		    struct sanlk_resource *res)
{
	int fd, rv, datalen;

	datalen = sizeof(struct sanlk_resource) +
		  sizeof(struct sanlk_disk) * res->num_disks;

	rv = connect_socket(&fd);
	if (rv < 0)
		return rv;

	rv = send_header(fd, SM_CMD_REQUEST, flags, datalen, force_mode, 0);
	if (rv < 0)
		goto out;

	rv = send(fd, res, sizeof(struct sanlk_resource), 0);
	if (rv < 0) {
		rv = -errno;
		goto out;
	}

	rv = send(fd, res->disks, sizeof(struct sanlk_disk) * res->num_disks, 0);
	if (rv < 0) {
		rv = -errno;
		goto out;
	}

	rv = recv_result(fd);
 out:
	close(fd);
	return rv;
}
开发者ID:gdahlm,项目名称:sanlock,代码行数:33,代码来源:client.c


示例5: do_get

static int
do_get(int cfd, const char *path, int path_len)
{
  send_header(cfd, OK);

  return 0;
}
开发者ID:natezzz,项目名称:Napoleon,代码行数:7,代码来源:response.c


示例6: sizeof

void XETP::send_world_room(OutStreamP out,WorldP world,
                           const RoomIndex &idx,int worldVersion) {
  u_int len = sizeof(int) +             // version
    Rooms::get_write_length() +       // rooms
    RoomIndex::get_write_length() +   // roomIndex
    Dim::get_write_length() +         // dim
    world->get_write_length(idx);     // world room data

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->prepare_packet(XETP::add_header(len));
  }

  send_header(out,WORLD_ROOM,len);
  out->write_int(worldVersion);
  Rooms rooms = world->get_rooms();
  rooms.write(out);
  idx.write(out);
  Dim dim = world->get_dim();
  dim.write(out);
  world->write(out,idx); // write one room

  if (out->get_protocol() == GenericStream::UDP) {
    ((UDPOutStreamP)out)->done_packet();
  }
}
开发者ID:toppk,项目名称:xevil,代码行数:25,代码来源:xetp.cpp


示例7: send_page

/* Send html page to client*/
void send_page(int socket)
{
  FILE * fp;

  /* Searchs for page in directory htdocs*/
  sprintf(buf_tmp,"htdocs/%s",req_buf);

  #if DEBUG
  printf("send_page: searching for %s\n",buf_tmp);
  #endif

  /* Verifies if file exists*/
  if((fp=fopen(buf_tmp,"rt"))==NULL) {
    /* Page not found, send error to client*/
    printf("send_page: page %s not found, alerting client\n",buf_tmp);
    not_found(socket);
  }
  else {
    /* Page found, send to client*/

    /* First send HTTP header back to client*/
    send_header(socket);

    printf("send_page: sending page %s to client\n",buf_tmp);
    while(fgets(buf_tmp,SIZE_BUF,fp))
      send(socket,buf_tmp,strlen(buf_tmp),0);

      /* Close file*/
      fclose(fp);
    }

    return;

  }
开发者ID:gabrieloliveirapinto,项目名称:Projecto,代码行数:35,代码来源:Server.c


示例8: wo_bwmbackup

void wo_bwmbackup(char *url)
{
	struct stat st;
	time_t t;
	int i;

	if (stat(hfn, &st) == 0) {
		t = st.st_mtime;
		sleep(1);
	}
	else {
		t = 0;
	}
	killall("rstats", SIGHUP);
	for (i = 10; i > 0; --i) {
		if ((stat(hfn, &st) == 0) && (st.st_mtime != t)) break;
		sleep(1);
	}
	if (i == 0) {
		send_error(500, NULL, NULL);
		return;
	}
	send_header(200, NULL, mime_binary, 0);
	do_file((char *)hfn);
}
开发者ID:NieHao,项目名称:Tomato-RAF,代码行数:25,代码来源:bwm.c


示例9: wo_iptbackup

void wo_iptbackup(char *url)
{
	struct stat st;
	time_t t;
	int i;

	if (stat(ifn, &st) == 0) {
		t = st.st_mtime;
		sleep(1);
	}
	else {
		t = 0;
	}
	killall("cstats", SIGHUP);
	for (i = 20; i > 0; --i) { // may take a long time for gzip to complete
		if ((stat(ifn, &st) == 0) && (st.st_mtime != t)) break;
		sleep(1);
	}
	if (i == 0) {
		send_error(500, NULL, NULL);
		return;
	}
	send_header(200, NULL, mime_binary, 0);
	do_file((char *)ifn);
}
开发者ID:NieHao,项目名称:Tomato-RAF,代码行数:25,代码来源:bwm.c


示例10: read_directory_files

static int
read_directory_files(tcp_con_t *con,const char *parent,GnomeVFSFileInfo *info) {
  int rc;
  char *rel_path;
  char *full_path;
  char *res_message;

  if ( (!con) || (!parent) || (!info) )
    return -EINVAL;

  if ( (!strcmp("..",info->name)) || (!strcmp(".",info->name) ) )
    return -EINVAL;

  if (info->type==GNOME_VFS_FILE_TYPE_REGULAR) {
    rc=create_response(IPMSG_FILE_REGULAR,info->name,info->size,parent,&res_message);
    if (rc<0)
      return rc;
    dbg_out("Send file:%s\n",res_message);
    rc=send_header(con,res_message);
    g_free(res_message);
    if (rc<0)
      return rc;
  }

  rc=-ENOMEM;
  full_path=g_build_filename(parent,info->name,NULL);
  if (!full_path) 
    return rc;
  /* send file */
  tcp_transfer_file(con,full_path,info->size,0);
  g_free(full_path);
  return 0;
}
开发者ID:girish946,项目名称:g2ipmsg,代码行数:33,代码来源:tcp.c


示例11: fetch_file

int fetch_file(int connfd, const char *filename) {
    int fd, fsize;
    struct stat fs;
    void *mblock;
    const char *mime_type, *suffix;
    int i;

    fd = open(filename, O_RDONLY);
    fstat(fd, &fs);
    fsize = fs.st_size;
    mblock = mmap(NULL, fsize, PROT_WRITE, MAP_PRIVATE, fd, 0);
    if (mblock == MAP_FAILED) {
        close(fd);
        send_error(connfd, 404);
        return 0;
    }

    suffix = filename;
    for (i = (int) strlen(filename) - 1; i >= 0; --i) {
        if (filename[i] == '.') {
            suffix = filename + i;
            break;
        }
    }

    if (strcasecmp(suffix, ".html") == 0 || strcasecmp(suffix, ".htm") == 0) {
        mime_type = "text/html";
    } else if (strcasecmp(suffix, ".css") == 0) {
        mime_type = "text/css";
    } else if (strcasecmp(suffix, ".js") == 0) {
        mime_type = "application/x-javascript";
    } else if (strcasecmp(suffix, ".c") == 0 || strcasecmp(suffix, ".h") == 0) {
        mime_type = "text/plain";
    } else {
        mime_type = "application/octet-stream";
    }

    send_response(connfd, 200, NULL);
    send_header(connfd, "Content-Type", mime_type);
    send_header(connfd, "Content-Length", "%d", fsize);
    end_headers(connfd);

    rio_writen(connfd, mblock, fsize);
    munmap(mblock, fsize);

    return 1;
}
开发者ID:foreverbell,项目名称:playground,代码行数:47,代码来源:http-server.c


示例12: pack_and_send

int pack_and_send(int sockfd, char *msg, uint32_t tag, uint32_t flags, struct packet *buf)
{
				int sent=0;
				pack_msg(msg, tag, flags, buf);
				sent += send_header(sockfd, buf);
				sent += send_msg(sockfd, msg);
				return sent;
}
开发者ID:norseboar,项目名称:swift_coasters,代码行数:8,代码来源:coaster_client.c


示例13: snprintf

void SensorsMessageProcessor::list_sensors() {
  // We don't support sensors yet so we mark all as disabled
  int mask = 0;
  char buf[12];
  snprintf(buf, sizeof(buf), "%d", mask);
  send_header(strlen(buf));
  messenger_->send(buf, strlen(buf));
  finish_message();
}
开发者ID:FWangZil,项目名称:anbox,代码行数:9,代码来源:sensors_message_processor.cpp


示例14: send_file

static int
send_file(struct http_request *req)
{
	int r;
	off_t file_size = -1;
	int fd;

	// open the requested url for reading
	// if the file does not exist, send a 404 error using send_error
	// if the file is a directory, send a 404 error using send_error
	// set file_size to the size of the file

	// LAB 6: Your code here.
	char path[MAXPATHLEN];                                                
        struct Stat stat;
        strcpy(path, req->url);  

	cprintf("Reached in send_file...path = %s\n", path);

        if ((fd = open(path, O_RDONLY)) < 0) {
		cprintf("Failed to open so sending 404...\n");
                send_error(req, 404);
                r = fd;
		close(fd);
		return r;
        }

        if ((r = fstat(fd, &stat)) < 0) {
		cprintf("Failed to get stat so sending 404...\n");
		close(fd);
		return r;
        }

        if (stat.st_isdir) {
		cprintf("it is a directory so sending 404...\n");
                send_error(req, 404);
                r = -1;
		close(fd);
		return r;
        }

        file_size = stat.st_size;

	if ((r = send_header(req, 200)) < 0 || (r = send_size(req, file_size)) < 0 || (r = send_content_type(req)) < 0 || (r = send_header_fin(req)) < 0) {
		cprintf("sending failed so sending 404...\n");
		close(fd);
		return r;
	}

	r = send_data(req, fd);
	close(fd);

	cprintf("send_file() successful...\n");
	return r;

	panic("send_file not implemented");
}
开发者ID:ajsbu,项目名称:cse506,代码行数:57,代码来源:httpd.c


示例15: wo_favicon

static void wo_favicon(char *url)
{
	if (nvram_match("web_favicon", "1")) {
		send_header(200, NULL, "image/vnd.microsoft.icon", 0);
		do_file(url);
	}
	else {
		send_error(404, NULL, NULL);
	}
}
开发者ID:twtomato,项目名称:twtomato,代码行数:10,代码来源:tomato.c


示例16: send_response

void send_response(FILE *f, int status, char *title, char *extra, char *text)
{
    send_header(f, status, title, extra, "text/html", -1, -1);
    fprintf(f, "<html>");
    set_simple_head(f, title, text, NULL);
    fprintf(f, "<body>");
    fprintf(f, "<h1>%d - %s</h1>", status, title);//naughty HTML
    fprintf(f, "<p>%s\r\n</p>", text);
    fprintf(f, "</body></html>");
}
开发者ID:psukys,项目名称:http_server,代码行数:10,代码来源:server.c


示例17: common_redirect

void common_redirect(void)
{
	if (atoi(webcgi_safeget("_ajax", ""))) {
		send_header(200, NULL, mime_html, 0);
		web_puts("OK");
	}
	else {
		redirect(webcgi_safeget("_redirect", "/"));
	}
}
开发者ID:twtomato,项目名称:twtomato,代码行数:10,代码来源:tomato.c


示例18: send_file

static int
send_file(struct http_request *req)
{
	int r;
	off_t file_size = -1;
	int fd;
	struct Stat stat;
	// open the requested url for reading
	// if the file does not exist, send a 404 error using send_error
	// if the file is a directory, send a 404 error using send_error
	// set file_size to the size of the file

	// LAB 6: Your code here.
	fd = open(req->url, O_RDONLY);
	//struct Fd *open_file = INDEX2FD(i);	
	if(fd < 0)
	{
		cprintf("file %s does not exists\n",req->url);
		r = send_error(req, 404);
		if(r<0)
			cprintf("send_file:send_error failed:%e\n",r);
	}
	r = fstat(fd, &stat);
	if(r<0)
	{
		cprintf("send_file:fstat failed:%e\n",r);
		r = send_error(req, 404);
	}
	if(stat.st_isdir == 1)
	{
		cprintf("file %s is a directory\n",req->url);
		 r = send_error(req, 404);
                if(r<0)
                        cprintf("send_file:send_error failed:%e\n",r);
	}
	file_size = stat.st_size;
	
	if ((r = send_header(req, 200)) < 0)
		goto end;

	if ((r = send_size(req, file_size)) < 0)
		goto end;

	if ((r = send_content_type(req)) < 0)
		goto end;

	if ((r = send_header_fin(req)) < 0)
		goto end;

	r = send_data(req, fd);

end:
	close(fd);
	return r;
}
开发者ID:GeneralYun,项目名称:x64-JOS-Labs-Project,代码行数:55,代码来源:httpd.c


示例19: send_file

static int
send_file(struct http_request *req)
{
	int r;
	off_t file_size = -1;
	int fd;

	// open the requested url for reading
	// if the file does not exist, send a 404 error using send_error
	// if the file is a directory, send a 404 error using send_error
	// set file_size to the size of the file

	// LAB 6: Your code here.

	char path[MAXPATHLEN];                                                 
        struct Stat stat;
        memmove(path, req->url, strlen(req->url));  

	if ((fd = open(path, O_RDONLY)) < 0) {
		send_error(req, 404);  // HTTP page not found
		r = fd;
		goto end;
	}

	if ((r = fstat(fd, &stat)) < 0) {
		goto end;
	}

	if (stat.st_isdir) {
		send_error(req, 404); // HTTP page not found
		r = -1;
		goto end;
	}

	file_size = stat.st_size;

	if ((r = send_header(req, 200)) < 0)
		goto end;

	if ((r = send_size(req, file_size)) < 0)
		goto end;

	if ((r = send_content_type(req)) < 0)
		goto end;

	if ((r = send_header_fin(req)) < 0)
		goto end;

	r = send_data(req, fd);

end:
	close(fd);
	return r;
}
开发者ID:pombredanne,项目名称:jos,代码行数:54,代码来源:httpd.c


示例20: send_command

void send_command(int throttle, int leftright, int forwardbackward)
{
	send_header();
	// TODO: finish...
	send_one();
	send_one();
	send_zero();
	send_zero();
	//send_zero();
	//send_one();
}
开发者ID:JavaWarrior,项目名称:stm32-test,代码行数:11,代码来源:main.c



注:本文中的send_header函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ send_headers函数代码示例发布时间:2022-05-30
下一篇:
C++ send_frame函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap