void CursesRenderer::drawMessage(const std::string & message) { std::string text = wrapText(message, this->width() / 2); std::vector<std::string> msgBuf; boost::split(msgBuf, text, boost::is_any_of("\n")); unsigned int width = 0; for (auto & s : msgBuf) width = (s.size() > width ? s.size() : width); width += 2; int msgHeight = msgBuf.size(); int height = 2 + msgHeight; startWindow(this->width() / 2 - width / 2, this->height() / 2 - height / 2, width, height); style(Colour::White, Colour::Black, Style::Normal); wborder(win(), 0,0,0,0,0,0,0,0); mvwaddstr(win(), 1, 1, text.c_str()); endWindow(); }
/* PURPOSE: To secure port 'PORT_NUMBER' to listen to clients, to make * 'NUM_CLIENTS' POSIX threads to handle that number of clients, to * display the number of chars processed by either thread as they are * processed, and to close windowing, mutex locking and the socket when * finished. Returns EXIT_SUCCESS on succes or EXIT_FAILURE otherwise. */ int main () { int socketDs; int clientIn; int clientIn1; pthread_t clientThread[NUM_CLIENTS]; if ( (socketDs = startServer()) == -1 ) { fprintf(stderr,"Error connecting to socket.\n"); return(EXIT_FAILURE); } startWindow(); int connectDs = accept(socketDs,NULL,NULL); doServer(connectDs); stopWindow(); stopServer(socketDs); return(EXIT_SUCCESS); }