Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. fd_set readset, writeset;
  2. FD_ZERO(&readset);
  3. FD_SET(JohnDoe.read_fd(), &readset);
  4. FD_SET(JoeSmith.read_fd(), &readset);
  5. FD_SET(JaneSmith.read_fd(), &readset);
  6. FD_ZERO(&writeset);
  7. FD_SET(JohnDoe.write_fd(), &writeset);
  8. FD_SET(JoeSmith.write_fd(), &writeset);
  9. FD_SET(JaneSmith.write_fd(), &writeset);
  10.  
  11. int maxfd = 0;
  12. maxfd = max(maxfd, JohnDoe.read_fd());
  13. maxfd = max(maxfd, JohnDoe.write_fd());
  14. maxfd = max(maxfd, JoeSmith.read_fd());
  15. maxfd = max(maxfd, JoeSmith.write_fd());
  16. maxfd = max(maxfd, JaneSmith.read_fd());
  17. maxfd = max(maxfd, JaneSmith.write_fd());
  18.  
  19. int numready;
  20. int count = 0;
  21. while (count < 10) {
  22. numready = select(maxfd + 1, &readset, &writeset, NULL, NULL);
  23. if (numready == -1) {
  24. cout << "Fatal error, abortingn";
  25. break;
  26. }
  27. else {
  28. if(FD_ISSET(JohnDoe.write_fd(), &writeset)) { //write_fd() returns write file descriptor
  29. JohnDoe.cwrite("data John Doe"); //one RequestChannel object
  30. }
  31. if(FD_ISSET(JoeSmith.write_fd(), &writeset)) {
  32. JoeSmith.cwrite("data Joe Smith");
  33. }
  34. if(FD_ISSET(JaneSmith.write_fd(), &writeset)) {
  35. JaneSmith.cwrite("data JaneSmith");
  36. }
  37.  
  38.  
  39.  
  40. if(FD_ISSET(JohnDoe.read_fd(), &readset)) {
  41. string s = JohnDoe.cread();
  42. cout << "John Doe cread: " << s << "n";
  43. }
  44. if(FD_ISSET(JoeSmith.read_fd(), &readset)) {
  45. string s = JoeSmith.cread();
  46. cout << "Joe Smith cread: " << s << "n";
  47. }
  48. if(FD_ISSET(JaneSmith.read_fd(), &readset)) {
  49. string s = JaneSmith.cread();
  50. cout << "Jane Smith cread: " << s << "n";
  51. }
  52. }
  53. }
  54.  
  55. fd_set readset, writeset;
  56.  
  57. int maxfd = 0;
  58. maxfd = max(maxfd, JohnDoe.read_fd());
  59. maxfd = max(maxfd, JohnDoe.write_fd());
  60. maxfd = max(maxfd, JoeSmith.read_fd());
  61. maxfd = max(maxfd, JoeSmith.write_fd());
  62. maxfd = max(maxfd, JaneSmith.read_fd());
  63. maxfd = max(maxfd, JaneSmith.write_fd());
  64.  
  65. int numready;
  66. int count = 0;
  67. while (count < 10) {
  68. FD_ZERO(&readset);
  69. FD_SET(JohnDoe.read_fd(), &readset);
  70. FD_SET(JoeSmith.read_fd(), &readset);
  71. FD_SET(JaneSmith.read_fd(), &readset);
  72. FD_ZERO(&writeset);
  73. FD_SET(JohnDoe.write_fd(), &writeset);
  74. FD_SET(JoeSmith.write_fd(), &writeset);
  75. FD_SET(JaneSmith.write_fd(), &writeset);
  76.  
  77. numready = select(maxfd + 1, &readset, &writeset, NULL, NULL);
  78.  
  79. // etc...
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement