📄 client.c
字号:
#include <threads/io.h>#include <threads/buffer.h>#include <threads/signal_num.h>#include <iostream>extern "C" {# include <stdarg.h># include <fcntl.h># include <termios.h># include <unistd.h># include <sys/syslog.h># include <sys/types.h># include <sys/stat.h>};using namespace std;using namespace cpp_threads;class client : public PthreadIO {protected: void close(cpp_threads::Socket& fd_p) { cout << "Connection closed by peer" << endl; PthreadIO::close(fd_p); /* Doing an exit here, will not terminate the application as we are actually being called as the server process. */ Pthread::_main()->signal(s_terminate); } void got(cpp_threads::SocketBuffer& p_fd) { while( !p_fd.inputBuf().empty() ) cout << p_fd.inputBuf().getline() << endl; }public: client() : PthreadIO("localhost",80) { }; ~client() { close(fd()); };};intmain(){ char buf[80]; PthreadIO *iop; cout << "This is an example client program, written in threads C++" << endl; cout << "Enter text, at the '?' prompt, and press enter. Enter '.'" << endl; cout << "to close the connection, and end the program." << endl << endl; cout << "Remember, no bad language." << endl; iop = new client; do { usleep(10); cout << "?"; cout.flush(); cin.getline(buf,80); if( cin ) { if( buf[0] != '.' && buf[0] != '\0' ) iop->put( buf ); } else cin.clear(); } while( buf[0] != '.' ); if ( !cin ) cout << "Input error: " << cin.rdstate() << endl; delete iop; usleep(10);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -