#include <assert.h>
#include "config.h"
#include "liblogging.h"
#include "sockets.h"
#include "beepsession.h"
#include "beepchannel.h"
#include "beepframe.h"
#include "beeplisten.h"
#include "namevaluetree.h"
#include "stringbuf.h"
#include "syslogmessage.h"
Functions | |
srRetVal | sbLstnOnFramRcvd (sbLstnObj *pThis, int *pbAbort, sbSessObj *pSess, sbFramObj *pFram) |
Lowest level event handler when a new frame arrived. | |
srRetVal | sbLstnBuildFrame (sbLstnObj *pThis, sbSessObj *pSess, char c, int *pbAbort) |
This method build a frame by processing one character at a time. | |
srRetVal | sbLstnDoIncomingData (sbLstnObj *pThis, sbSessObj *pSess) |
Receive all incoming data that is available. | |
srRetVal | sbSessAddActiveSession (sbLstnObj *pThis, sbSessObj *pSess) |
Add a session to the list of active sessions. | |
srRetVal | sbLstnSendFram (sbLstnObj *pThis, sbSessObj *pSess) |
Actually send a frame over the socket. | |
srRetVal | sbLstnServerLoop (sbLstnObj *pThis) |
This is the main server/IO handler. | |
sbLstnObj * | sbLstnConstruct (void) |
Construct a sbLstnObj. | |
void | sbLstnDestroy (sbLstnObj *pThis) |
Destructor for the beep listener object. | |
srRetVal | sbLstnInit (sbLstnObj *pThis) |
Initialize a listener. | |
srRetVal | sbLstnRun (sbLstnObj *pThis) |
THE listener process. | |
srRetVal | sbLstnExit (sbLstnObj *pThis) |
Exit the listener. | |
srRetVal | sbLstnAddProfile (sbLstnObj *pThis, sbProfObj *pProf) |
Actually, this module implements all the listeners. The initial release did only care about BEEP, but starting with 0.6.0 additional listeners are supported. In 0.6.0 at least a standard UDP listener has been added. Other listeners (eventually not implemented by the time you read this) are the simple syslog over TCP (aka "SELP") and the local /var/log "listener" on *nix.
Please see architecture::c for more details.
2003-09-26 Changed the logical meaning of this module. It is no longer the BEEP listener, only. It is now *the* listener for all supported protocols. This allows us to keep all listeners on a single thread.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Adiscon GmbH or Rainer Gerhards nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
This method build a frame by processing one character at a time. It operates on a continuous stream of data. It is a state machine. As soon as a full frame is detected, the frame handler is called which then should pass the data to his upper layer - or whatever he intends to do with it. This is not the business of this method. For each new frame, new memory is allocated, so the frame handler (or its upper layers) are responsible for deleting the frame. This method calls itself recursively if it needed to peek at a character and now needs to do the actual processing.
|
|
Construct a sbLstnObj. This MUST be the first call a server makes. After the server has obtained the sbLstnObj, it can set the parameters and THEN call sbLstnInit().
|
|
Receive all incoming data that is available. This method reads all available incoming data and processes it. It will call receive state machine to form new frames. That machine, in turn, will fire off Receive events as full frames are completely received. Please note that it is possible for a single run of this method to receive no, one or more full frames. < actual number of bytes received < set by lower layer methods if a fatal error occured. in this case, the session should be aborted and such the full buffer needs not to be processed. < receive buffer - this could be any size, we have selected this size so that an ethernet frame fits. Feel free to tune. |
|
Exit the listener. Will do all cleanup necessary. |
|
Initialize a listener. The listener socket is created, but it is not yet set to listen() to incoming calls.
|
|
Lowest level event handler when a new frame arrived. This handler must first verify if it is a good packet (checks like seqno sequence and thus) and if so, find the profile that it should send data to. SEQ frames are directly processed and channel 0 protocol is mapped to fixed handlers in this object itself. Please note: the message object created here is passed on to the upper layers. However, these upper layers MUST NOT destroy the Mesg Object - this will be done once this method finishes!
|
|
THE listener process.
|
|
Actually send a frame over the socket. If the method would block, we could only send a partial frame.
|
|
This is the main server/IO handler. This loop is executed until termination is flagged. This is the ONLY method that is responsible for scheduling IO. The loop has three phases:
We have some OS dependant code in here. The reason is that "original" BSD sockets need to have passed the highest numbered file descriptor. We can not properly emulate this in the socket layer. Even if we could, that would potentially cause a considerable performance hit. Thus, we implement it in this module and pass it on to the lower layer. If we run into a non BSD-sockets OS other than Windows, we might be not so happy with this decision, but lets try it... Please note that all send operations are only done in phase 1.
|