-
class
ReflectServer
(Return to index)
-
This class represents a reflection server: It runs on a centrally located machine,and many clients may connect to it simultaneously. This server can then redirect messagesuploaded by any client to other clients in a somewhat efficient manner.
Type:
Include file:
../../reflector/ReflectServer.h
Synopsis:
Public methods:
- public virtual void
Cleanup ()
Should be called just before the ReflectServer is to be destroyed.
this in a good place to put any cleanup code. Be sure
to call Cleanup() of your parent class as well!
(We can't just do this in the destructor, as some cleanup
relies on the subclass still being functional, which it isn't
when our destructor gets called!)
- public virtual status_t
ReadyToRun ()
Called after the server is set up, but just before accepting any connections.
Should return B_NO_ERROR if it's okay to continue, or B_ERROR to abort.
Default implementation returns B_NO_ERROR.
- public
ReflectServer ()
- public virtual status_t
ServerProcessLoop (ReflectSessionFactoryFunc createSessionFunc, short acceptPort = 2960)
The main loop for the message reflection server.
Returns B_ERROR if there was a problem setting up. This method will not return until the server stops running (usually due to an error)
(acceptPort) is the port the server will listen on.
(createSessionFunc) should be a function of the form:
AbstractReflectSession * MyFunc();
that returns a new AbstractReflectSession object to be used for communicating with
the given socket. The object this function returns determines the semantics of the server.
Most non-abstract ReflectSession classes come with such a function.
- public
~ReflectServer ()
Protected methods:
- protected virtual status_t
AddNewSession (AbstractReflectSessionRef ref)
This version of AddNewSession (which is called by the previous
version) assumes that the gateway, hostname, port, etc of the
new session have already been set up.
- protected virtual status_t
AddNewSession (AbstractReflectSessionRef ref, int socket)
Adds a new session that uses the given socket for I/O.
If (socket) is -1, no TCP connection will be used.
- protected void
EndSession (AbstractReflectSession * which)
Called by a session to get itself removed & destroyed
- protected virtual void
GetPulseTime (const struct timeval & now, struct timeval & returnTime)
May be overridden to specify when Pulse() should next be called.
(now) is the current time of day.
(returnTime) should be modified to reflect the time at which Pulse() should
next be called. If it is set to (0,0), then no Pulse() call will be scheduled.
Default version returns the next schedule time for any attached i/o gateway
that wants Pulse() events. If you override this method, please call up to
this method implementation, and only change the return value yourself if your
wakeup time is before the (returnTime) you get.
- protected virtual const char *
GetServerName () const
Returns a human-readable string that describes the type of server that
is running. Default implementation returns "MUSCLE".
- protected PortableQueue<AbstractReflectSessionRef> &
GetSessionsList ()
Returns our contained list of active sessions.
- protected virtual void
Pulse (const struct timeval & now)
If GetPulseTime() was overridden, then this callback will be called at
(or shortly after) the time that GetPulseRate() specified.
(now) is the current time of day. Default implementation calls Pulse()
on any i/o gateways that scheduled Pulse() events.
- protected status_t
ReplaceSession (AbstractReflectSessionRef newSession, AbstractReflectSession * replaceThisOne)
Called by a session to get itself replaced (the
new session will continue using the same message io streams
as the old one)
Returns B_NO_ERROR on success, B_ERROR if the new session
returns an error in its AttachedToServer() method. If
B_ERROR is returned, then this call is guaranteed not to
have had any effect on the old session.
Friend methods: