-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.cpp
More file actions
60 lines (52 loc) · 1.97 KB
/
http.cpp
File metadata and controls
60 lines (52 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* http.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fbouanan <fbouanan@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/17 18:36:47 by fbouanan #+# #+# */
/* Updated: 2023/03/17 18:36:59 by fbouanan ### ########.fr */
/* */
/* ************************************************************************** */
#include"http.hpp"
Http::Http(){
}
void Http::create_socket()
{
fd_server = ::socket(AF_INET,SOCK_STREAM,0);
if (fd_server == -1)
{
std::cerr<<"can't Create a socket."<<std::endl;
exit(2);
}
fcntl(fd_server, F_SETFL, O_NONBLOCK);
}
void Http::naming_socket(struct sockaddr_in address )
{
def_socket = address;
}
void Http::bind(Pserver &conf)
{
int use = 1;
struct addrinfo hints;
memset(&hints,0,sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo* results;
setsockopt(fd_server,SOL_SOCKET,SO_REUSEADDR, &use,sizeof(use));
std::cout<<conf.host.c_str()<<std::endl;
int status = getaddrinfo(conf.host.c_str(), "http", &hints, &results);
//(void)status;
if (status != 0) {
std::cerr << "Failed to perform DNS lookup: " << gai_strerror(status) << std::endl;
exit(2); ;
}
if (::bind(fd_server,(struct sockaddr *)&def_socket,sizeof(def_socket)) < 0)
{
std::cerr<<"can't bind socket with def_socket."<<std::endl;
exit(2);
}
}
Http::~Http(){
}