Linux heracles.o2switch.net 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
/
opt
/
alt
/
ruby21
/
share
/
ri
/
2.1.0
/
system
/
GServer
/
//opt/alt/ruby21/share/ri/2.1.0/system/GServer/cdesc-GServer.ri
U:RDoc::NormalClass[iI"GServer:ET@I"Object;To:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[ I"LGServer implements a generic server, featuring thread pool management, ;TI"Esimple logging, and multi-server management. See HttpServer in ;TI"R<tt>xmlrpc/httpserver.rb</tt> in the Ruby standard library for an example of ;TI"GServer in action.;To:RDoc::Markup::BlankLine o; ;[I"OAny kind of application-level server can be implemented using this class. ;TI"RIt accepts multiple simultaneous connections from clients, up to an optional ;TI"Pmaximum number. Several _services_ (i.e. one service per TCP port) can be ;TI"Jrun simultaneously, and stopped at any time through the class method ;TI"P<tt>GServer.stop(port)</tt>. All the threading issues are handled, saving ;TI"Qyou the effort. All events are optionally logged, but you can provide your ;TI"$own event handlers if you wish.;T@S:RDoc::Markup::Heading: leveli: textI"Example;T@o; ;[I"PUsing GServer is simple. Below we implement a simple time server, run it, ;TI"9query it, and shut it down. Try this code in +irb+:;T@o:RDoc::Markup::Verbatim;[$I"require 'gserver' ;TI" ;TI"# ;TI"=# A server that returns the time in seconds since 1970. ;TI"# ;TI" class TimeServer < GServer ;TI") def initialize(port=10001, *args) ;TI" super(port, *args) ;TI" end ;TI" def serve(io) ;TI" io.puts(Time.now.to_i) ;TI" end ;TI" end ;TI" ;TI"E# Run the server with logging enabled (it's a separate thread). ;TI"server = TimeServer.new ;TI"=server.audit = true # Turn logging on. ;TI"server.start ;TI" ;TI"R# *** Now point your browser to http://localhost:10001 to see it working *** ;TI" ;TI""# See if it's still running. ;TI"4GServer.in_service?(10001) # -> true ;TI"5server.stopped? # -> false ;TI" ;TI"(# Shut the server down gracefully. ;TI"server.shutdown ;TI" ;TI"+# Alternatively, stop it immediately. ;TI"GServer.stop(10001) ;TI"%# or, of course, "server.stop". ;T:@format0o; ;[I"OAll the business of accepting connections and exception handling is taken ;TI"Rcare of. All we have to do is implement the method that actually serves the ;TI"client.;T@S;;i; I" Advanced;T@o; ;[ I"MAs the example above shows, the way to use GServer is to subclass it to ;TI"Pcreate a specific server, overriding the +serve+ method. You can override ;TI"Oother methods as well if you wish, perhaps to collect statistics, or emit ;TI"more detailed logging.;T@o:RDoc::Markup::List: @type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0;[o; ;[I"#connecting;To;;0;[o; ;[I"#disconnecting;To;;0;[o; ;[I"#starting;To;;0;[o; ;[I"#stopping;T@o; ;[I"KThe above methods are only called if auditing is enabled, via #audit=.;T@o; ;[I"NYou can also override #log and #error if, for example, you wish to use a ;TI"'more sophisticated logging system.;T: @fileI"lib/gserver.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[ I" audit;TI"RW;T:publicFI"lib/gserver.rb;T[ I" debug;TI"RW;T;F@s[ I" host;TI"R;T;F@s[ I"maxConnections;TI"R;T;F@s[ I" port;TI"R;T;F@s[ I"stdlog;TI"RW;T;F@s[U:RDoc::Constant[i I"DEFAULT_HOST;FI"GServer::DEFAULT_HOST;T00o;;[ ;@n;0@n@cRDoc::NormalClass0[ [[I" class;T[[;[[I"in_service?;F@s[I"new;T@s[I" stop;F@s[:protected[ [:private[ [I" instance;T[[;[[I"connections;F@s[I" join;F@s[I" serve;F@s[I" shutdown;F@s[I" start;F@s[I" stop;F@s[I" stopped?;F@s[;[[I"connecting;F@s[I"disconnecting;F@s[I" error;F@s[I"log;F@s[I" starting;F@s[I" stopping;F@s[;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[@n@ncRDoc::TopLevel