本文整理汇总了C++中send_header函数的典型用法代码示例。如果您正苦于以下问题:C++ send_header函数的具体用法?C++ send_header怎么用?C++ send_header使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_header函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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;
}
示例5: do_get
static int
do_get(int cfd, const char *path, int path_len)
{
send_header(cfd, OK);
return 0;
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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");
}
示例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);
}
}