Example #1
0
/*
 * Core function to get the status of a mailbox.
 */
static int
ifcore_status(lua_State *lua)
{
	int r;
	unsigned int exists, recent, unseen, uidnext;

	exists = recent = unseen = uidnext = -1;

	if (lua_gettop(lua) != 2)
		luaL_error(lua, "wrong number of arguments");
	luaL_checktype(lua, 1, LUA_TLIGHTUSERDATA);
	luaL_checktype(lua, 2, LUA_TSTRING);

	while ((r = request_status((session *)(lua_topointer(lua, 1)),
	    lua_tostring(lua, 2), &exists, &recent, &unseen, &uidnext)) ==
	    STATUS_NONE);

	lua_pop(lua, 2);

	if (r == -1)
		return 0;

	lua_pushboolean(lua, (r == STATUS_OK));
	lua_pushinteger(lua, (lua_Integer) (exists));
	lua_pushinteger(lua, (lua_Integer) (recent));
	lua_pushinteger(lua, (lua_Integer) (unseen));
	lua_pushinteger(lua, (lua_Integer) (uidnext));

	return 5;
}
void M3LedX2XNEcShm::SetSdsFromStatus(unsigned char * data)
{  
  status_to_sds.timestamp = GetBaseStatus()->timestamp(); 
  

  
  
  M3LedX2XNEcShmSdsStatus * sds = (M3LedX2XNEcShmSdsStatus *) data;
  request_status();  
  memcpy(sds, &status_to_sds, GetStatusSdsSize());  
  release_status();

}
Example #3
0
/*
 * Core function to get the status of a mailbox.
 */
static int
ifcore_status(lua_State *lua)
{
	const char *s, *u, *p;
	int r;
	unsigned int exists, recent, unseen, uidnext;

	exists = recent = unseen = uidnext = -1;

	if (lua_gettop(lua) != 2)
		luaL_error(lua, "wrong number of arguments");

	luaL_checktype(lua, 1, LUA_TTABLE);
	luaL_checktype(lua, 2, LUA_TSTRING);

	lua_pushvalue(lua, 1);
	if (!(s = get_table_string("server")))
		luaL_error(lua, "no mail server specified");
	if (!(u = get_table_string("username")))
		luaL_error(lua, "no username specified");
	p = DISCOVER_PORT(get_table_string("port"), get_table_string("ssl"));
	lua_pop(lua, 1);

	r = request_status(s, p, u, lua_tostring(lua, 2), &exists, &recent,
	    &unseen, &uidnext);

	lua_pop(lua, 2);

	lua_pushboolean(lua, (r == STATUS_RESPONSE_OK));
	lua_pushnumber(lua, (lua_Number) (exists));
	lua_pushnumber(lua, (lua_Number) (recent));
	lua_pushnumber(lua, (lua_Number) (unseen));
	lua_pushnumber(lua, (lua_Number) (uidnext));

	return 5;
}
Example #4
0
/* return xmlrpc status struct on success, xmlrpc error struct on failure */
xmlrpc_value *
status_get(xmlrpc_env * envP, struct call_info *cip)
{
  char *fname = NULL, *buf = NULL;
  int res = -1;
  struct stat st;
  xmlrpc_value *s;

  trace();
  if (!cip)
    return request_error(envP, "oracc-xmlrpc: status_get: NULL call_info", NULL);
  trace();
  if (!cip->session)
    return request_error(envP, "oracc-xmlrpc: status_get: no session set in call_info", NULL);
  trace();
  fname = status_file(cip);
  if ((res = stat(fname, &st)) < 0)
    return request_error(envP, "oracc-xmlrpc: unable to stat status for session %s\n%s", cip->session, strerror(errno), NULL);
  trace();
  buf = malloc((size_t)st.st_size + 1);
  if ((res = open(fname, O_RDONLY)) < 0)
    return request_error(envP, "oracc-xmlrpc: unable to read status for session %s\n%s", cip->session, strerror(errno), NULL);
  trace();
  if ((res = read(res, buf, st.st_size)) < 0)
    return request_error(envP, "oracc-xmlrpc: read of %d bytes failed for session %s\n%s", (int)st.st_size, cip->session, strerror(errno), NULL);
  buf[st.st_size] = '\0';
  fprintf(stderr, "status_get: read status `%s'\n", buf);
  trace();
  s = request_status(envP, "OK", NULL);

  if (!strcmp(buf, "completed"))
    method_files(envP, s);

  method_status(envP, s, "%s", buf, NULL);
  return s;
}
Example #5
0
void ServerWidget::xonotic_connected()
{
    xonotic_clear();
    set_network_status(tr("Connected"));
    request_status();
}
void M3TorqueShm::SetSdsFromStatus(unsigned char * data)
{  
  status_to_sds.timestamp = GetBaseStatus()->timestamp(); 
  
  for (int i = 0; i < bot->GetNdof(RIGHT_ARM); i++)
  {    
    status.mutable_right_arm()->set_theta(i, bot->GetThetaDeg(RIGHT_ARM,i));
    status.mutable_right_arm()->set_thetadot(i, bot->GetThetaDotDeg(RIGHT_ARM,i));
    status.mutable_right_arm()->set_torque(i, bot->GetTorque_mNm(RIGHT_ARM,i));
    status.mutable_right_arm()->set_ctrl_mode(i, bot->GetMode(RIGHT_ARM,i));
    status_to_sds.right_arm.theta[i] = status.right_arm().theta(i);
    status_to_sds.right_arm.thetadot[i] = status.right_arm().thetadot(i);
    status_to_sds.right_arm.torque[i] = status.right_arm().torque(i);
    status_to_sds.right_arm.ctrl_mode[i] = status.right_arm().ctrl_mode(i);
  }
  if (right_loadx6)
  {
    for (int i = 0; i < 6; i++)
    {
      status.mutable_right_arm()->set_loadx6(i, right_loadx6->GetWrench(i));
      status_to_sds.right_arm.wrench[i] = right_loadx6->GetWrench(i);
    }

  }
  for (int i = 0; i < bot->GetNdof(LEFT_ARM); i++)
  {    
    status.mutable_left_arm()->set_theta(i, bot->GetThetaDeg(LEFT_ARM,i));
    status.mutable_left_arm()->set_thetadot(i, bot->GetThetaDotDeg(LEFT_ARM,i));
    status.mutable_left_arm()->set_torque(i, bot->GetTorque_mNm(LEFT_ARM,i));
    status.mutable_left_arm()->set_ctrl_mode(i, bot->GetMode(LEFT_ARM,i));
    status_to_sds.left_arm.theta[i] = status.left_arm().theta(i);
    status_to_sds.left_arm.thetadot[i] = status.left_arm().thetadot(i);
    status_to_sds.left_arm.torque[i] = status.left_arm().torque(i);
    status_to_sds.left_arm.ctrl_mode[i] = status.left_arm().ctrl_mode(i);
  }
  if (left_loadx6)
  {
    for (int i = 0; i < 6; i++)
    {
      status.mutable_left_arm()->set_loadx6(i, left_loadx6->GetWrench(i));
      status_to_sds.left_arm.wrench[i] = left_loadx6->GetWrench(i);
    }
  }
  for (int i = 0; i < bot->GetNdof(TORSO); i++)
  {    
    status.mutable_torso()->set_theta(i, bot->GetThetaDeg(TORSO,i));
    status.mutable_torso()->set_thetadot(i, bot->GetThetaDotDeg(TORSO,i));
    status.mutable_torso()->set_torque(i, bot->GetTorque_mNm(TORSO,i));
    status.mutable_torso()->set_ctrl_mode(i, bot->GetMode(TORSO,i));
    status_to_sds.torso.theta[i] = status.torso().theta(i);
    status_to_sds.torso.thetadot[i] = status.torso().thetadot(i);
    status_to_sds.torso.torque[i] = status.torso().torque(i);
    status_to_sds.torso.ctrl_mode[i] = status.torso().ctrl_mode(i);
  }
  
  for (int i = 0; i < bot->GetNdof(HEAD); i++)
  {    
    status.mutable_head()->set_theta(i, bot->GetThetaDeg(HEAD,i));
    status.mutable_head()->set_thetadot(i, bot->GetThetaDotDeg(HEAD,i));
    status.mutable_head()->set_torque(i, bot->GetTorque_mNm(HEAD,i));
    status.mutable_head()->set_ctrl_mode(i, bot->GetMode(HEAD,i));
    status_to_sds.head.theta[i] = status.head().theta(i);
    status_to_sds.head.thetadot[i] = status.head().thetadot(i);
    status_to_sds.head.torque[i] = status.head().torque(i);
    status_to_sds.head.ctrl_mode[i] = status.head().ctrl_mode(i);
  }
  
  M3TorqueShmSdsStatus * sds = (M3TorqueShmSdsStatus *) data;
  request_status();  
  memcpy(sds, &status_to_sds, GetStatusSdsSize());  
  release_status();
	

}
Example #7
0
static
#endif
int status_client_ncurses_main_loop(struct async *as,
	struct asfd *so_asfd, struct sel *sel,
	const char *orig_client)
{
	int ret=-1;
	char *client=NULL;
	int count=0;
	struct asfd *asfd=NULL;
	struct asfd *sfd=NULL; // Server asfd.
	int reqdone=0;

	if(!sel
	  || !as
	  || !(stdout_asfd=so_asfd)
	  || !(sfd=as->asfd))
	{
		logp("parameters not set up correctly in %s\n", __func__);
		goto error;
	}

	sel->page=PAGE_CLIENT_LIST;

	if(orig_client)
	{
		client=strdup_w(orig_client, __func__);
		sel->page=PAGE_BACKUP_LIST;
	}

	if(json_input_init()) goto end;

	while(1)
	{
		if(need_status(sel) && !reqdone)
		{
			char *req=NULL;
			if(sel->page>PAGE_CLIENT_LIST)
			{
				if(client)
					req=client;
				else if(sel->client)
					req=sel->client->name;
			}
			if(request_status(sfd, req, sel))
				goto error;

			// We only want to start on the client the user gave to
			// us. Freeing it will allow the user to browse other
			// clients thereafter.
			free_w(&client);

			if(actg==ACTION_STATUS_SNAPSHOT)
				reqdone=1;
		}

		if(as->read_write(as))
		{
			// FIX THIS - an exception is thrown when the console
			// is resized.
/*
			if(sfd->want_to_remove)
			{
				sfd->want_to_remove=0;
				continue;
			}
*/
			logp("Exiting main loop\n");
			goto error;
		}

		for(asfd=as->asfd; asfd; asfd=asfd->next)
		{
			while(asfd->rbuf->buf)
			{
				switch(parse_data(asfd, sel, count))
				{
					case 0: break;
					case 1: goto end;
					default: goto error;
				}
				iobuf_free_content(asfd->rbuf);
				if(asfd->parse_readbuf(asfd))
					goto error;
			}

			// Select things if they are not already selected.
			if(sel->client)
			{
				if(!sel->backup)
					sel->backup=sel->client->bu;
			}
			else
				sel->client=sel->clist;
		}

#ifdef HAVE_NCURSES
		if(actg==ACTION_STATUS
		  && update_screen(sel))
			goto error;
		refresh();
#endif

		if(actg==ACTION_STATUS_SNAPSHOT
		  && sel->client)
		{
			if(update_screen(sel))
				goto error;
			stdout_asfd->write_str(stdout_asfd, CMD_GEN, "\n");
			break;
		}
	}

end:
	ret=0;
error:
	json_input_free();
	return ret;
}
Example #8
0
int status_client_ncurses(struct config *conf, enum action act, const char *sclient)
{
	int fd=0;
        int ret=0;
	int sel=0;
	char *rbuf=NULL;
	char buf[512]="";
	int count=0;
	int details=0;
	char *last_rbuf=NULL;
	int srbr=0;
	char *client=NULL;
	int enterpressed=0;
//	int loop=0;
	int reqdone=0;

#ifdef HAVE_NCURSES_H
	int stdinfd=fileno(stdin);
	actg=act; // So that the sighandler can call endwin().
#else
	if(act==ACTION_STATUS)
	{
		printf("To use the live status monitor, you need to recompile with ncurses support.\n");
		return -1;
	}
#endif

	setup_signals();

	/* NULL == ::1 or 127.0.0.1 */
	if((fd=init_client_socket(NULL, conf->status_port))<0)
		return -1;
	set_non_blocking(fd);

#ifdef HAVE_NCURSES_H
	if(actg==ACTION_STATUS)
	{
		initscr();
		start_color();
		init_pair(1, COLOR_WHITE, COLOR_BLACK);
		init_pair(2, COLOR_WHITE, COLOR_BLACK);
		init_pair(3, COLOR_WHITE, COLOR_BLACK);
		raw();
		keypad(stdscr, TRUE);
		noecho();
		curs_set(0);
		halfdelay(3);
		//nodelay(stdscr, TRUE);
	}
#endif
#ifdef DBFP
	dbfp=fopen("/tmp/dbfp", "w");
#endif

	while(!ret)
	{
		int l;
		int mfd=-1;
		fd_set fsr;
		fd_set fse;
		struct timeval tval;

		// Failsafe to prevent the snapshot ever getting permanently
		// stuck.
		//if(act==ACTION_STATUS_SNAPSHOT && loop++>10000)
		//	break;

		if(sclient && !client)
		{
			client=strdup(sclient);
			details=1;
		}

		if((enterpressed || need_status()) && !reqdone)
		{
			char *req=NULL;
			if(details && client) req=client;
			if(request_status(fd, req, conf))
			{
				ret=-1;
				break;
			}
			enterpressed=0;
			if(act==ACTION_STATUS_SNAPSHOT)
				reqdone++;
		}

		FD_ZERO(&fsr);
		FD_ZERO(&fse);

		tval.tv_sec=1;
		tval.tv_usec=0;

		add_fd_to_sets(fd, &fsr, NULL, &fse, &mfd);
#ifdef HAVE_NCURSES_H
		if(actg==ACTION_STATUS)
			add_fd_to_sets(stdinfd, &fsr, NULL, &fse, &mfd);
#endif

		if(select(mfd+1, &fsr, NULL, &fse, &tval)<0)
		{
			if(errno!=EAGAIN && errno!=EINTR)
			{
				logp("select error: %s\n",
					strerror(errno));
				ret=-1;
				break;
			}
			continue;
		}

		if(FD_ISSET(fd, &fse))
		{
			ret=-1;
			break;
		}

#ifdef HAVE_NCURSES_H
		if(actg==ACTION_STATUS)
		{
			if(FD_ISSET(stdinfd, &fse))
			{
				ret=-1;
				break;
			}
			if(FD_ISSET(stdinfd, &fsr))
			{
				int quit=0;
				
				switch(getch())
				{
					case 'q':
					case 'Q':
						quit++;
						break;
					case KEY_UP:
					case 'k':
					case 'K':
						if(details) break;
						sel--;
						break;
					case KEY_DOWN:
					case 'j':
					case 'J':
						if(details) break;
						sel++;
						break;
					case KEY_ENTER:
					case '\n':
					case ' ':
						if(details) details=0;
						else details++;
						enterpressed++;
						break;
					case KEY_LEFT:
					case 'h':
					case 'H':
						details=0;
						break;
					case KEY_RIGHT:
					case 'l':
					case 'L':
						details++;
						break;
					case KEY_NPAGE:
					{
						int row=0, col=0;
						getmaxyx(stdscr, row, col);
						sel+=row-TOP_SPACE;
						break;
					}
					case KEY_PPAGE:
					{
						int row=0, col=0;
						getmaxyx(stdscr, row, col);
						sel-=row-TOP_SPACE;
						break;
					}
				}
				if(quit) break;

				if(sel<0) sel=0;
				if(sel>=count) sel=count-1;

				// Attempt to print stuff to the screen right
				// now, to give the impression of key strokes
				// being responsive.
				if(!details && !sclient)
				{
				  if((srbr=show_rbuf(last_rbuf,
					conf, sel, &client,
					&count, details, sclient))<0)
				  {
					ret=-1;
					break;
				  }
				  if(!details) print_star(sel);
				
				  refresh();
				}
			}
		}
#endif

		if(FD_ISSET(fd, &fsr))
		{
			// ready to read.
			if((l=read(fd, buf, sizeof(buf)-1))>0)
			{
				size_t r=0;
				buf[l]='\0';
				if(rbuf) r=strlen(rbuf);
				rbuf=(char *)realloc(rbuf, r+l+1);
				if(!r) *rbuf='\0';
				strcat(rbuf+r, buf);
			}
			else
				break;

			if(act==ACTION_STATUS_SNAPSHOT)
			{
				if(rbuf)
				{
					if(!strcmp(rbuf, "\n"))
					{
						// This happens when there are
						// no backup clients.
						break;
					}
					if(strstr(rbuf, "\n-list end-\n"))
					{
						printf("%s", rbuf);
						break;
					}
				}
				continue;
			}

			//if(rbuf) printf("rbuf: %s\n", rbuf);
/*
			if(l<0)
			{
				ret=-1;
				break;
			}
*/
		}

		if((srbr=show_rbuf(rbuf, conf,
			sel, &client, &count, details, sclient))<0)
		{
			ret=-1;
			break;
		}
		else if(srbr)
		{
			// Remember it, so that we can present the detailed
			// screen without delay, above.
			if(last_rbuf) free(last_rbuf);
			last_rbuf=rbuf;
			rbuf=NULL;
		}

		if(sclient) details++;

		usleep(20000);
#ifdef HAVE_NCURSES_H
		if(actg==ACTION_STATUS)
		{
			flushinp();
			continue;
		}
#endif
		if(count)
		{
			printf("\n");
			break;
		}
	}
#ifdef HAVE_NCURSES_H
	if(actg==ACTION_STATUS) endwin();
#endif
	close_fd(&fd);
	if(last_rbuf) free(last_rbuf);
	if(rbuf) free(rbuf);
#ifdef DBFP
	if(dbfp) fclose(dbfp);
#endif
	return ret;
}
Example #9
0
static int main_loop(struct async *as, enum action act, struct conf **confs)
{
	int ret=-1;
	char *client=NULL;
	int count=0;
	struct asfd *asfd=NULL;
	struct asfd *sfd=as->asfd; // Server asfd.
	int reqdone=0;
	struct sel *sel=NULL;
	const char *orig_client=get_string(confs[OPT_ORIG_CLIENT]);

	if(!(sel=(struct sel *)calloc_w(1, sizeof(struct sel), __func__)))
		goto error;
	sel->page=PAGE_CLIENT_LIST;

	if(orig_client && !client)
	{
		client=strdup_w(orig_client, __func__);
		sel->page=PAGE_BACKUP_LIST;
	}

	while(1)
	{
		if(need_status(sel) && !reqdone)
		{
			char *req=NULL;
			if(sel->page>PAGE_CLIENT_LIST)
			{
				if(client) req=client;
				else if(sel->client) req=sel->client->name;
			}
			if(request_status(sfd,
				req, sel, confs)) goto error;
			if(act==ACTION_STATUS_SNAPSHOT)
				reqdone=1;
		}

		if(as->read_write(as))
		{
			// FIX THIS - an exception is thrown when the console
			// is resized.
/*
			if(sfd->want_to_remove)
			{
				sfd->want_to_remove=0;
				continue;
			}
*/
			logp("Exiting main loop\n");
			goto error;
		}

		for(asfd=as->asfd; asfd; asfd=asfd->next)
			while(asfd->rbuf->buf)
		{
			switch(parse_data(asfd, sel, count))
			{
				case 0: break;
				case 1: goto end;
				default: goto error;
			}
			iobuf_free_content(asfd->rbuf);
			if(asfd->parse_readbuf(asfd))
				goto error;
		}

		if(!sel->client) sel->client=sel->clist;
		if(!sel->backup && sel->client) sel->backup=sel->client->bu;

#ifdef HAVE_NCURSES_H
		if(act==ACTION_STATUS
		  && update_screen(sel, confs))
			goto error;
		refresh();
#endif

		if(act==ACTION_STATUS_SNAPSHOT
		  && sel->gotfirstresponse)
		{
			if(update_screen(sel, confs))
				goto error;
			// FIX THIS - should probably set up stdout with an
			// asfd.
			printf("\n");
			break;
		}
	}

end:
	ret=0;
error:
	// FIX THIS: should probably be freeing a bunch of stuff here.
	free_v((void **)&sel);
	return ret;
}
Example #10
0
int main(int argc, char *argv[]) {

	int sockfd, portno;
	socklen_t cli_len;
	char req_buffer[MAXBUFLEN];
	char resp_buffer[MAXBUFLEN];
	struct sockaddr_in serv_addr, cli_addr;
	cli_len = sizeof(cli_addr);
	int numbytes_req, numbytes_resp;
	fd_set rfds;
	struct timeval tv = { 0L, 0L };
	FD_ZERO(&rfds);
	FD_SET(0, &rfds);
	
	if (argc != 3){
        	printf( "Usage: %s <port> <destination>\n", argv[0] );
        	fprintf(stderr,"ERROR, wrong # of arguments!\n");
        	return -1;
     	}
	char *serv_dir = argv[2];

	if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
		perror("sws: error on socket()");
		return -1;
	}
	//printf("established sockfd: %i\n", sockfd);

	bzero((char *) &serv_addr, sizeof(serv_addr));
	portno = atoi(argv[1]);
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_addr.s_addr = inet_addr("10.10.1.100");
	serv_addr.sin_port = htons(portno); // byte order
	
	// bind to a socket with reusability option
	int optval = 1;
	setsockopt(sockfd,SOL_SOCKET, (SO_REUSEPORT|SO_REUSEADDR), &optval,sizeof(optval));
	if (bind(sockfd,(struct sockaddr *) &serv_addr,
			sizeof(serv_addr)) < 0) {
		close(sockfd);
		perror("sws: error on binding!");
		return -1;
	}
	
	printf("sws is running on UDP port %i and serving %s\nPress q + ENTER to quit\n",
		portno, serv_dir);

	bool quit = false;
	while(!quit) {
		fflush(stdout);
		// receive then format a packet
		if ((numbytes_req = recvfrom(sockfd, req_buffer, MAXBUFLEN-1, 0,
				(struct sockaddr *)&cli_addr, &cli_len)) == -1) {
			perror("sws: error on recvfrom()!");
			close(sockfd);
			return -1;
		}
		req_buffer[numbytes_req]='\0';
		
		// parse response
		// example req: "GeT /test.txt HtTp/1.0" 
		std::string request_line = std::string(req_buffer);
		int first_space = request_line.find_first_of(" \t");
		int first_new_l = request_line.find_first_of("\r\n");
		// use iteration to find first non ws before first newl
		int i = first_new_l-1;
		while (i > 0) {
			if (isspace(request_line[i]))
				break;
			i--;
		}
		int last_space  = i;
		std::string method = request_line.substr(0,first_space);
		size_t uri_len = last_space-1-method.length();
		std::string uri = request_line.substr(first_space+1,uri_len);
		size_t version_len = first_new_l-method.length()-uri.length()-2;
		std::string version = request_line.substr(last_space+1,version_len);

		// correct a special case
		if (uri == "/") {
			uri = "/index.html";
		}

		// get ready to send response
		std::string file_name_to_print = uri; 
		std::string response_string = "HTTP/1.0 ";
		int status = request_status(request_line,method,uri,version);	
		if (status) { // bad request
			response_string+= "400 Bad Request\n";
		} else if (uri.find("../") != std::string::npos) { // cannot access root
			response_string+= "404 Not Found\n";
		} else { 
			// get file contents
			char dir_buffer[MAXBUFLEN]; 
			strcpy(dir_buffer,serv_dir);
			strcat(dir_buffer,uri.c_str());
			
			if( access( dir_buffer, F_OK ) != -1 ) {
 				// file exists
				char *file_contents;
				long input_file_size;
				FILE *input_file = fopen(dir_buffer, "rb");
				fseek(input_file, 0, SEEK_END);
				input_file_size = ftell(input_file);
				rewind(input_file);
				file_contents = (char*) malloc((input_file_size+1) * (sizeof(char)));
				fread(file_contents, sizeof(char), input_file_size, input_file);
				fclose(input_file);
				file_contents[input_file_size] = 0;	
				response_string+= "200 OK\n\n";
				response_string+= file_contents;

				//needed for server output
				file_name_to_print = std::string(dir_buffer);
			} else {
				// file doesn't exist
				response_string+= "404 Not Found\n";
			}	

		}
		// the actual message we send
		strcpy(resp_buffer,response_string.c_str());		
		resp_buffer[response_string.length()] = 0; 

		// send back a packet
		if ((numbytes_resp = sendto(sockfd,resp_buffer,strlen(resp_buffer), 0,
				(struct sockaddr *)&cli_addr, cli_len)) == -1) {
			perror("sws: error in sendto():");
			close(sockfd);
			return -1;
		}

		// print details of msg and response
		req_buffer[numbytes_req-1]=0; 		// format to print
		resp_buffer[response_string.find("\n")]=0; // format to print
		printf("%s %s:%d %s; %s; %s\n",get_time_string(),
			inet_ntoa(cli_addr.sin_addr), ntohs(cli_addr.sin_port),
			req_buffer, resp_buffer,file_name_to_print.c_str());

		// Quit Server? 
		// You have to PRESS ENTER AND receive a packet to register a quit !!!
		FD_ZERO(&rfds);
		FD_SET(0, &rfds);
		int retval = select(1,&rfds, NULL, NULL, &tv);
		if (retval) {	
			char buff[MAXBUFLEN] = {0};
			int len;
			fgets(buff, sizeof(buff), stdin);
			len = strlen(buff) - 1;
			if (buff[len] == '\n')
				buff[len] = '\0';
			printf("\n! server operator input: %s\n",buff);
			if (strchr(buff,'Q')!= NULL || strchr(buff,'q')!= NULL) {
				quit = true;
			}
		}

	}
	printf("\nServer is closed.\n");
	close(sockfd);
	return 0;
}