⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clients.c

📁 用c++包装好的线程库,直接拿来使用,提高效率.
💻 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)    {      cout << '<' << id() << '>' <<  p_fd.inputBuf().getline() << endl;    }public:  client() : PthreadIO("localhost",31000) { };  ~client() { close(fd()); };};intmain(){  PthreadIO *iop[16];  int i;  cout << "Multiple connection performance test." << endl << endl;  cout << "This program will open up sevral connection to the Threads" << endl;  cout << "server program and send a specific message through all" << endl;  cout << "of them." << endl;  for( i = 0;i < 16;i++ )    iop[i] = new client;  for( i=0;i < 16;i++ )    iop[i&15]->put("halo\n");  sleep(10);  for( i=0;i < 16;i++ )    delete iop[i];  usleep(10);  cout << "The server should show, that the messages were delivered." << endl;  cout << "Possibly not in the same order as connected, which means" << endl;  cout << "that connections were queued, and delivered later as the" << endl;  cout << "application became ready to accept connections." << endl;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -