00001 // 00002 // plumbing - C++ wrapper facades for Berkeley sockets 00003 // Copyright (C) 2009 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify it 00006 // under the terms of the GNU General Public License, version 3, as published 00007 // by the Free Software Foundation. 00008 // 00009 // This program is distributed in the hope that it will be useful, but WITHOUT 00010 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00012 // more details. 00013 // 00014 // You should have received a copy of the GNU General Public License along with 00015 // this program. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #include <cstdio> 00019 #include <cstdlib> 00020 #include <unistd.h> 00021 00022 #include <libplumbing/reactor.h> 00023 #include <libplumbing/endpoint/client/stdout.h> 00024 #include <libplumbing/logging.h> 00025 #include <libplumbing/progname.h> 00026 #include <libplumbing/version_print.h> 00027 00028 00029 static void 00030 usage() 00031 { 00032 std::string prog = plumbing::progname_get(); 00033 fprintf(stderr, "Usage: %s <hostname> <port>\n", prog.c_str()); 00034 fprintf(stderr, " %s -V\n", prog.c_str()); 00035 exit(1); 00036 } 00037 00038 00039 int 00040 main(int argc, char **argv) 00041 { 00042 plumbing::progname_set(argv[0]); 00043 for (;;) 00044 { 00045 int c = getopt(argc, argv, "V"); 00046 if (c == EOF) 00047 break; 00048 switch (c) 00049 { 00050 case 'V': 00051 plumbing::version_print(); 00052 return 0; 00053 00054 default: 00055 usage(); 00056 } 00057 } 00058 std::string hostname; 00059 std::string port; 00060 switch (argc - optind) 00061 { 00062 case 2: 00063 hostname = argv[optind]; 00064 port = argv[optind + 1]; 00065 break; 00066 00067 default: 00068 usage(); 00069 // NOTREACHED 00070 } 00071 00072 // 00073 // This is the simplest main loop that can be achieved with the 00074 // Plumbing library. 00075 // 00076 // The reactor is instantiated, the endpoint is created, and the 00077 // reactor is told to manage the endpoint. 00078 // 00079 // The reactor then runs until there are no more endpoints to be 00080 // managed. When they are done, endpoints remove themselves from 00081 // the select loop. 00082 // 00083 plumbing::reactor fat_controller; 00084 plumbing::endpoint::pointer thomas = 00085 plumbing::endpoint_client_stdout::create(hostname, port); 00086 fat_controller.add_endpoint(thomas); 00087 fat_controller.run(); 00088 return 0; 00089 } 00090 00091 00092 // vim: set tw=8 sw=4 et