Skip to content
Snippets Groups Projects
Commit 4ec5ab7a authored by Joey Le's avatar Joey Le
Browse files

Impmeneted boot server hopefully

parent ecb0d781
Branches
No related tags found
No related merge requests found
......@@ -206,6 +206,12 @@ int execute_pipeline(command_list_t *clist) {
return OK;
}
static void start_server() {
int listen_socket;
int ret;
}
/****
**** FOR REMOTE SHELL USE YOUR SOLUTION FROM SHELL PART 3 HERE
**** THE MAIN FUNCTION CALLS THIS ONE AS ITS ENTRY POINT TO
......
......@@ -50,11 +50,6 @@ int start_server(char *ifaces, int port, int is_threaded){
int svr_socket;
int rc;
//
//TODO: If you are implementing the extra credit, please add logic
// to keep track of is_threaded to handle this feature
//
svr_socket = boot_server(ifaces, port);
if (svr_socket < 0){
int err_code = svr_socket; //server socket will carry error code
......@@ -117,11 +112,35 @@ int stop_server(int svr_socket){
int boot_server(char *ifaces, int port){
int svr_socket;
int ret;
struct sockaddr_in addr;
// TODO set up the socket - this is very similar to the demo code
svr_socket = socket(AF_INET, SOCK_STREAM, 0);
if (svr_socket == -1) {
perror("socket");
return ERR_RDSH_SERVER;
}
int enable = 1;
if (setsockopt(svr_socket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
perror("setsockopt");
close(svr_socket);
return ERR_RDSH_SERVER;
}
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr(ifaces);
addr.sin_port = htons(port);
ret = bind(svr_socket, (const struct sockaddr *) &addr, sizeof(struct sockaddr_in));
if (ret == -1 ) {
perror("bind");
close(svr_socket);
return ERR_RDSH_SERVER;
}
/*
* Prepare for accepting connections. The backlog size is set
* to 20. So while one request is being processed other requests
......@@ -133,6 +152,7 @@ int boot_server(char *ifaces, int port){
return ERR_RDSH_COMMUNICATION;
}
printf("SERVER BOOTED on %s:%d\n", ifaces, port);
return svr_socket;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment