-- CHATZILLA CHANGES ONLY --

removed dead libbs code (bug 39364)
partial fix for bug 47673, still blocked by bug 49410
fix for bug 46541
This commit is contained in:
rginda%netscape.com 2000-08-22 23:58:02 +00:00
parent f7cf2c4b48
commit b89555b48f
31 changed files with 25 additions and 3906 deletions

View File

@ -97,7 +97,7 @@ function (outer, iid) {
function IRCContentHandler ()
{}
IRCContentHandler.prototype.queryInterface =
IRCContentHandler.prototype.QueryInterface =
function (iid) {
if (!iid.equals(nsIContentHandler))
@ -199,7 +199,7 @@ function BogusChannel (aURI)
this.originalURI = aURI;
}
BogusChannel.prototype.queryInterface =
BogusChannel.prototype.QueryInterface =
function (iid) {
if (!iid.equals(nsIChannel) && !iid.equals(nsIRequest) &&

View File

@ -60,6 +60,8 @@ function CBSConnection ()
this._sockService = sockService.QueryInterface
(Components.interfaces.nsISocketTransportService);
this.wrappedJSObject = this;
}
CBSConnection.prototype.connect = function(host, port, bind, tcp_flag)
@ -161,11 +163,14 @@ CBSConnection.prototype.readData = function(timeout)
return rv;
}
CBSConnection.prototype.startAsyncRead =
function (server)
if (jsenv.HAS_DOCUMENT)
{
this._channel.asyncRead (new StreamListener (server), this);
CBSConnection.prototype.startAsyncRead =
function (server)
{
this._channel.asyncRead (new StreamListener (server), this);
}
}
function StreamListener(server)
@ -189,7 +194,15 @@ function (channel, ctxt, status, errorMsg)
StreamListener.prototype.onDataAvailable =
function (channel, ctxt, inStr, sourceOffset, count)
{
if (!this.lastInStr)
ctxt = ctxt.wrappedJSObject;
if (!ctxt)
{
dd ("*** Can't get wrappedJSObject from ctxt in " +
"StreamListener.onDataAvailable ***");
return;
}
if (!ctxt._inputStream)
ctxt._inputStream = toScriptableInputStream (inStr);
var ev = new CEvent ("server", "data-available", this.server,
@ -197,4 +210,3 @@ function (channel, ctxt, inStr, sourceOffset, count)
ev.line = ctxt.readData(0);
this.server.parent.eventPump.addEvent (ev);
}

View File

@ -88,7 +88,7 @@ function init(obj)
obj.networks["efnet"] =
new CIRCNetwork ("efnet", [
{name: "irc.idle.net", port: 6667},
{name: "irc.mcs.net", port: 6667},
{name: "irc.cs.cmu.edu", port: 6667}],
obj.eventPump);

View File

@ -337,7 +337,8 @@ f = function (e)
}
bot.personality.addHook
(/(smile)|(rotfl)|(lmao)|(rotflmao)|(you(.)?re funny)|(look happy)|(you(.)?re smart)/i, f);
(/(smile)|(rotfl)|(lmao)|(rotflmao)|(look happy)|(you(.)?re smart)/i, f);
/* (/(smile)|(rotfl)|(lmao)|(rotflmao)|(you(.)?re funny)|(look happy)|(you(.)?re smart)/i, f); */
f = function (e)
{
@ -362,3 +363,5 @@ f = function (e)
}
bot.personality.addHook (/(look confused)|(i like windows)/i, f);
delete f;

View File

@ -1 +0,0 @@
Makefile

View File

@ -1 +0,0 @@
bsIConnection.idl

View File

@ -1,50 +0,0 @@
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Basic Socket Library
#
# The Initial Developer of the Original Code is New Dimensions Consulting,
# Inc. Portions created by New Dimensions Consulting, Inc. are Copyright (C) 1999
# New Dimenstions Consulting, Inc. All Rights Reserved.
#
# Contributor(s):
# Robert Ginda, rginda@ndcico.com, original author
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = bs
LIBRARY_NAME = bs
IS_COMPONENT = 1
CSRCS = \
bsutil.c \
bserror.c \
bsevent.c \
bsqueue.c \
bsnetwork.c \
bsserver.c \
bsconnection.c \
$(NULL)
CPPSRCS = \
bsXPCConnection.cpp \
bsXPCConnectionFactory.cpp \
$(NULL)
XPIDLSRCS = bsIConnection.idl
include $(topsrcdir)/config/rules.mk

View File

@ -1,36 +0,0 @@
CC = gcc
LD = gcc
CFLAGS = -Wall -g
DEFS = -DDEBUG
MOZROOT = /home/rginda/src/mozilla_HEAD/mozilla
#MOZROOT = /home/rginda/src/mozilla_DEV/mozilla
#MOZROOT = /data210/src/mozilla
MOZBIN = $(MOZROOT)/dist/bin
LDFLAGS = $(MOZBIN)/libnspr3.so -lpthread
INCLUDES = -I$(MOZROOT)/dist/include
OFILES = bsutil.o \
bserror.o \
bsevent.o \
bsqueue.o \
bsnetwork.o \
bsserver.o \
bsconnection.o
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) $(DEFS) -c $<
main: $(OFILES) main.c
$(CC) $(CFLAGS) $(INCLUDES) $(DEFS) $(OFILES) $(LDFLAGS) main.c -o main
clean:
rm -f *.o xpcom/*.o xpcom/libbs.so core main
realclean: clean
rm -f *~ xpcom/*~
tarball: realclean
cd ..; tar -czf bslib-current.tar.gz bslib

View File

@ -1,64 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#include "nsISupports.idl"
[scriptable, uuid(ACEDC9B0-395C-11D3-AEB9-0000F8E25C06)]
interface bsIConnection : nsISupports
{
attribute boolean isConnected;
attribute boolean linebufferFlag;
attribute unsigned short port;
void init (in string hostname);
void destroy ();
boolean disconnect();
boolean connect (in unsigned short port,
in string bindIP,
in boolean tcpFlag);
void sendData (in string data);
boolean hasData ();
string readData (in unsigned long timeout);
};
%{ C++
// {25b7b6e0-3af4-11d3-aeb9-0000f8e25c06}
#define BS_CONNECTION_CID \
{ 0x25b7b6e0, 0x3af4, 0x11d3, { 0xae, 0xb9, 0x0, 0x0, 0xf8, 0xe2, 0x5c, 0x6 }}
#define BS_CONNECTION_PROGID "component://misc/bs/connection"
#define BS_CONNECTION_CLASSNAME "bsConnection"
extern nsresult
BS_NewConnection(bsIConnection** aConnection);
%}

View File

@ -1,300 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
* Robert Ginda <rginda@ndcico.com> (original author)
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "prerror.h"
#include "plstr.h"
#include "nscore.h"
#include "nsMemory.h"
#include "bsIConnection.h"
#include "bsapi.h"
#include "bspubtd.h"
#include "bsconnection.h"
#include "bsserver.h"
#include "bserror.h"
#define BS_INIT_CHECK if (!mInitializedFlag) \
return NS_ERROR_FAILURE
class bsConnection : public bsIConnection
{
public:
bsConnection();
virtual ~bsConnection();
NS_DECL_ISUPPORTS
NS_IMETHOD Init(const char *hostname);
NS_IMETHOD Destroy();
NS_IMETHOD GetIsConnected(PRBool *aIsConnected);
NS_IMETHOD SetIsConnected(PRBool aIsConnected);
NS_IMETHOD GetLinebufferFlag(PRBool *aLinebufferFlag);
NS_IMETHOD SetLinebufferFlag(PRBool aLinebufferFlag);
NS_IMETHOD GetPort(PRUint16 *aPort);
NS_IMETHOD SetPort(PRUint16 aPort);
NS_IMETHOD Disconnect(PRBool *rval);
NS_IMETHOD Connect(PRUint16 port, const char *bindIP, PRBool tcpFlag,
PRBool *rval);
NS_IMETHOD SendData(const char *data);
NS_IMETHOD HasData(PRBool *_retval);
NS_IMETHOD ReadData(PRUint32 timeout, char **aData);
private:
BSConnectionClass *connection;
BSServerClass *server;
PRBool mInitializedFlag;
PRBool mDataFlag;
PRBool mData;
};
/* static constructor used by factory */
extern nsresult
BS_NewConnection(bsIConnection** aConnection)
{
NS_PRECONDITION(aConnection != nsnull, "null ptr");
if (!aConnection)
return NS_ERROR_NULL_POINTER;
*aConnection = new bsConnection();
if (!*aConnection)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aConnection);
return NS_OK;
}
bsConnection::bsConnection()
{
NS_INIT_REFCNT();
mInitializedFlag = PR_FALSE;
}
bsConnection::~bsConnection()
{
if (mInitializedFlag)
Destroy();
}
NS_IMPL_ISUPPORTS(bsConnection, NS_GET_IID(bsIConnection));
NS_IMETHODIMP
bsConnection::Init(const char *hostname)
{
if (mInitializedFlag)
return NS_ERROR_FAILURE;
server = bs_server_new (nsnull, hostname);
if (!server)
return NS_ERROR_OUT_OF_MEMORY;
connection = nsnull;
mInitializedFlag = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
bsConnection::Destroy()
{
if (mInitializedFlag)
bs_server_free (server);
return NS_OK;
}
NS_IMETHODIMP
bsConnection::GetIsConnected(PRBool *aIsConnected)
{
BS_INIT_CHECK;
bs_connection_get_bool_property (connection, BSPROP_STATUS, aIsConnected);
return NS_OK;
}
NS_IMETHODIMP
bsConnection::SetIsConnected(PRBool aIsConnected)
{
BS_INIT_CHECK;
bs_connection_set_bool_property (connection, BSPROP_STATUS, aIsConnected);
return NS_OK;
}
NS_IMETHODIMP
bsConnection::GetLinebufferFlag(PRBool *aLinebufferFlag)
{
BS_INIT_CHECK;
bs_connection_get_bool_property (connection, BSPROP_LINE_BUFFER,
aLinebufferFlag);
return NS_OK;
}
NS_IMETHODIMP
bsConnection::SetLinebufferFlag(PRBool aLinebufferFlag)
{
BS_INIT_CHECK;
bs_connection_set_bool_property (connection, BSPROP_LINE_BUFFER,
aLinebufferFlag);
return NS_OK;
}
NS_IMETHODIMP
bsConnection::GetPort(PRUint16 *aPort)
{
BS_INIT_CHECK;
bs_connection_get_uint_property (connection, BSPROP_PORT, aPort);
return NS_OK;
}
NS_IMETHODIMP
bsConnection::SetPort(PRUint16 aPort)
{
BS_INIT_CHECK;
bs_connection_set_uint_property (connection, BSPROP_PORT, aPort);
return NS_OK;
}
NS_IMETHODIMP
bsConnection::Disconnect(PRBool *rval)
{
BS_INIT_CHECK;
if (connection != (void *)0)
*rval = bs_connection_disconnect (connection);
else
*rval = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
bsConnection::Connect(PRUint16 port, const char *bindIP, PRBool tcpFlag,
PRBool *rval)
{
BS_INIT_CHECK;
connection = bs_server_connect(server, port, bindIP, tcpFlag);
*rval = (connection != (void *)0) ? PR_TRUE : PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
bsConnection::SendData(const char *data)
{
BS_INIT_CHECK;
if (!connection)
return NS_ERROR_FAILURE;
if (!bs_connection_send_string (connection, data))
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
bsConnection::HasData (PRBool *result)
{
PRPollDesc polld;
if (mDataFlag)
return PR_TRUE;
polld.fd = bs_connection_get_fd (connection);
polld.in_flags = PR_POLL_READ;
PRInt32 rv = PR_Poll (&polld, 1, PR_INTERVAL_NO_WAIT);
if (rv < 0)
{
BS_ReportPRError (PR_GetError());
return NS_ERROR_FAILURE;
}
*result = (polld.out_flags & PR_POLL_READ) ? PR_TRUE : PR_FALSE;
return PR_TRUE;
}
NS_IMETHODIMP
bsConnection::ReadData(PRUint32 timeout, char **aData)
{
NS_PRECONDITION (aData, "null ptr");
bschar *data;
bsint c = bs_connection_recv_data (connection, timeout, &data);
if (c < 0)
return NS_ERROR_FAILURE;
else
if (c == 0)
{
*aData = (char*) nsMemory::Alloc(1);
**aData = '\00';
}
else
{
*aData = (char*) nsMemory::Alloc(PL_strlen(data) + 1);
if (! *aData)
return NS_ERROR_OUT_OF_MEMORY;
PL_strcpy(*aData, data);
}
mDataFlag = PR_FALSE;
return NS_OK;
}

View File

@ -1,216 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
/*
* This is a blatent ripoff of nsSampleFactory.cpp
*/
#include "nsCOMPtr.h"
#include "nscore.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsXPComFactory.h"
#include "bsIConnection.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kConnectionCID, BS_CONNECTION_CID);
class bsConnectionFactory : public nsIFactory
{
public:
bsConnectionFactory (const nsCID &aClass, const char* className,
const char* progID);
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~bsConnectionFactory();
protected:
nsCID mClassID;
const char* mClassName;
const char* mProgID;
};
////////////////////////////////////////////////////////////////////////
bsConnectionFactory::bsConnectionFactory(const nsCID &aClass,
const char* className,
const char* progID)
: mClassID(aClass), mClassName(className), mProgID(progID)
{
NS_INIT_REFCNT();
}
bsConnectionFactory::~bsConnectionFactory()
{
}
NS_IMETHODIMP
bsConnectionFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(bsConnectionFactory);
NS_IMPL_RELEASE(bsConnectionFactory);
NS_IMETHODIMP
bsConnectionFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (!aResult)
return NS_ERROR_NULL_POINTER;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
*aResult = nsnull;
nsresult rv;
nsISupports *inst = nsnull;
if (mClassID.Equals(kConnectionCID)) {
if (NS_FAILED(rv = BS_NewConnection((bsIConnection**) &inst)))
return rv;
}
else {
return NS_ERROR_NO_INTERFACE;
}
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult))) {
// We didn't get the right interface.
NS_ERROR("didn't support the interface you wanted");
}
NS_IF_RELEASE(inst);
return rv;
}
nsresult bsConnectionFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// return the proper factory to the caller
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* aServMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if (!aFactory)
return NS_ERROR_NULL_POINTER;
bsConnectionFactory* factory = new bsConnectionFactory(aClass,
aClassName, aProgID);
if (factory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
{
nsresult rv;
/*
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
*/
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterComponent(kConnectionCID,
BS_CONNECTION_CLASSNAME,
BS_CONNECTION_PROGID,
aPath, PR_TRUE, PR_FALSE);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
{
nsresult rv;
/*
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
*/
NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterComponent(kConnectionCID, aPath);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}

View File

@ -1,59 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsapi_h___
#define bsapi_h___
PR_BEGIN_EXTERN_C
/* common properties */
#define BSPROP_PARENT 100
#define BSPROP_NAME 101
#define BSPROP_KEY 102
#define BSPROP_STATUS 103
/* network properties */
#define BSPROP_EVENTS_PER_STEP 200
/* server properties */
#define BSPROP_HOSTNAME 300
#define BSPROP_PORT 301
#define BSPROP_INPUT_TIMEOUT 302
#define BSPROP_LINE_BUFFER 303
/* connection properties */
/* event properties */
#define BSPROP_OBJECT_TYPE 400
#define BSPROP_DESTOBJECT 401
#define BSPROP_HANDLER_ID 402
#define BSPROP_DATA 403
#define BS_CHECK_TYPE(type, mask) (mask & type)
PR_END_EXTERN_C
#endif /* bsapi_h___ */

View File

@ -1,28 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>BSConnection Component sample page</title>
</head>
<body>
<h1>BSConnection Component test page</h1>
<script>
var connection =
Components.classes["component://misc/bs/connection"].createInstance();
connection = connection.QueryInterface(
Components.interfaces.bsIConnection);
for (i in Components.interfaces) dump (Components.interfaces[i]);
dump("connection = " + connection + "\n");
</script>
<hr>
<address><a href="mailto:rginda@ndcico.com"></a></address>
<!-- Created: Fri Jul 16 04:14:03 DST 1999 -->
<!-- hhmts start -->
Last modified: Fri Jul 16 05:42:13 DST 1999
<!-- hhmts end -->
</body>
</html>

View File

@ -1,45 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsconfig_h___
#define bsconfig_h___
PR_BEGIN_EXTERN_C
#define BS_CONNECTION_TIMEOUT_MS 30 * 1000 /* timeout for connect()s */
#define BS_SEND_TIMEOUT_MS 30 * 1000 /* timeout for send()s */
#define BS_RECV_TIMEOUT_MS 1 /* timeout for recv()s */
/* property defaults */
#define BS_EVENTS_PER_STEP_DEFAULT 3
#define BS_INPUT_TIMEOUT_DEFAULT 2000
#define BS_LINEBUFFER_FLAG_DEFAULT PR_TRUE
#define BSMAX_SERVER_RECV 4095
PR_END_EXTERN_C
#endif /* bsconfig_h___ */

View File

@ -1,530 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
* Simon Fraser, smfr@netscape.com, Mac warning fixes
*/
#include "string.h"
#include "prtypes.h"
#include "prerror.h"
#include "prmem.h"
#include "prio.h"
#include "prlog.h"
#include "bspubtd.h"
#include "bsutil.h"
#include "bsconfig.h"
#include "bserror.h"
#include "bsevent.h"
#include "bsqueue.h"
#include "bsapi.h"
#include "bsserver.h"
#include "bsconnection.h"
PR_BEGIN_EXTERN_C
BSConnectionClass *
bs_connection_new (BSServerClass *parent, PRFileDesc *fd, bsint port)
{
BSConnectionClass *new_connection;
new_connection = PR_NEW (BSConnectionClass);
if (!new_connection)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
memset (new_connection->callback_table, 0, BSCONNECTION_EVENT_COUNT);
new_connection->parent_server = parent;
new_connection->linebuffer = NULL;
new_connection->port = port;
new_connection->fd = fd;
new_connection->linebuffer_flag = BS_LINEBUFFER_FLAG_DEFAULT;
new_connection->is_connected = PR_TRUE;
return new_connection;
}
void
bs_connection_free (BSConnectionClass *connection)
{
PR_ASSERT (connection);
/* partially received line will be lost */
PR_FREEIF (connection->linebuffer);
bs_connection_disconnect (connection);
PR_Free (connection);
}
PRBool
bs_connection_disconnect (BSConnectionClass *connection)
{
PRStatus rv;
PR_ASSERT (connection);
if (connection->is_connected)
{
PR_FREEIF (connection->linebuffer);
rv = PR_Shutdown (connection->fd, PR_SHUTDOWN_BOTH);
if (PR_FAILURE == rv)
BS_ReportPRError (PR_GetError());
rv = PR_Close (connection->fd);
if (PR_FAILURE == rv)
BS_ReportPRError (PR_GetError());
}
connection->is_connected = PR_FALSE;
return PR_FALSE;
}
PRBool /* public method */
bs_connection_send_data (BSConnectionClass *connection, bschar *data,
bsuint length)
{
PRIntervalTime to;
PRInt32 count;
PR_ASSERT (connection);
to = PR_MillisecondsToInterval (BS_SEND_TIMEOUT_MS);
count = PR_Send (connection->fd, data, length, 0, to);
if (count == -1)
{
BS_ReportPRError (PR_GetError());
return PR_FALSE;
}
return PR_TRUE;
}
PRBool /* public method */
bs_connection_send_string (BSConnectionClass *connection, const bschar *data)
{
bsuint length;
PR_ASSERT (connection);
length = strlen (data);
return bs_connection_send_data (connection, (bschar *)data, length);
}
PRInt32 /* friend function */
bs_connection_recv_data (BSConnectionClass *connection, PRInt32 timeout,
bschar **buf)
{
PRIntervalTime to;
PRInt32 count;
PRErrorCode err;
static bschar recv_buf[BSMAX_SERVER_RECV];
PR_ASSERT (connection);
*buf = recv_buf;
to = PR_MillisecondsToInterval (timeout);
count = PR_Recv(connection->fd, recv_buf, BSMAX_SERVER_RECV, 0, to);
switch (count)
{
case -1: /* recv error */
err = PR_GetError();
switch (err)
{
case PR_IO_TIMEOUT_ERROR:
buf[0] = '\00';
count = 0;
break;
default:
BS_ReportPRError (err);
goto err_out;
break;
}
break;
case 0: /* connection closed */
count = -1;
goto err_out;
default: /* byte count */
((char *)(*buf))[count] = 0;
}
return count;
err_out:
*buf = NULL;
return count;
}
PRBool /* friend function */
bs_connection_recv (BSConnectionClass *connection, BSQueueClass *event_queue)
{
bschar *buf, *lastline = NULL;
bschar **lineary;
int i, lines;
BSEventClass *event;
PRBool completeline_flag;
PRInt32 count;
PR_ASSERT (connection);
count = bs_connection_recv_data (connection, BS_RECV_TIMEOUT_MS, &buf);
if (count == 0)
{
event = bs_event_new (BSOBJ_CONNECTION, connection,
BSEVENT_CONNECTION_DISCONNECT, NULL,
NULL, NULL);
if (!event)
return PR_FALSE;
if (0 == bs_queue_add (event_queue, event, 0))
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
return PR_FALSE;
}
if (count < 0)
{
BS_ReportError (BSERR_UNDEFINED_ERROR);
return PR_FALSE;
}
if (connection->linebuffer_flag)
{
completeline_flag = (buf[count - 1] == '\n') ? PR_TRUE :
PR_FALSE;
lineary = bs_util_delimbuffer_to_array (buf, &lines, '\n');
for (i = 0; i < lines - 1; i++)
{
event = bs_event_new_copyZ (BSOBJ_CONNECTION, connection,
BSEVENT_CONNECTION_RAWDATA,
lineary[i], NULL);
if (!event)
return PR_FALSE;
if (0 == bs_queue_add (event_queue, event, 0))
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
}
buf = lastline = bs_util_linebuffer (lineary[lines - 1],
&connection->linebuffer,
completeline_flag);
PR_Free (lineary);
}
if (buf)
{
connection->linebuffer = NULL;
event = bs_event_new_copyZ (BSOBJ_CONNECTION, connection,
BSEVENT_CONNECTION_RAWDATA,
buf, NULL);
if (!event)
return PR_FALSE;
if (0 == bs_queue_add (event_queue, event, 0))
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
}
PR_FREEIF (lastline);
return PR_TRUE;
}
PRFileDesc * /* friend function */
bs_connection_get_fd (BSConnectionClass *connection)
{
PR_ASSERT (connection);
if (!connection->is_connected)
return NULL;
return connection->fd;
}
BSEventClass *
bs_connection_route (BSConnectionClass *connection, BSEventClass *event)
{
PR_ASSERT (connection);
if ((event->id < BSCONNECTION_EVENT_COUNT) &&
(connection->callback_table[event->id]))
return connection->callback_table[event->id](connection, event);
else
return NULL;
}
PRBool
bs_connection_set_handler (BSConnectionClass *connection,
BSConnectionEvent event_type,
BSConnectionEventCallback *handler)
{
PR_ASSERT (connection);
if (event_type > BSCONNECTION_EVENT_COUNT)
{
BS_ReportError (BSERR_NO_SUCH_EVENT);
return PR_FALSE;
}
connection->callback_table[event_type] = handler;
return PR_TRUE;
}
PRBool
bs_connection_set_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bsint type, void *v)
{
PR_ASSERT (connection);
switch (prop)
{
case BSPROP_PARENT:
if (!BS_CHECK_TYPE (type, BSTYPE_OBJECT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
connection->parent_server = (BSServerClass *)v;
break;
case BSPROP_LINE_BUFFER:
if (!BS_CHECK_TYPE (type, BSTYPE_BOOLEAN))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
connection->linebuffer_flag = *(PRBool *)v;
break;
case BSPROP_STATUS:
if (!BS_CHECK_TYPE (type, BSTYPE_BOOLEAN))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
BS_ReportError (BSERR_READ_ONLY);
return PR_FALSE;
break;
case BSPROP_PORT:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
if (connection->is_connected)
{
BS_ReportError (BSERR_READ_ONLY);
return PR_FALSE;
}
connection->port = *(bsuint *)v;
break;
default:
BS_ReportError (BSERR_NO_SUCH_PARAM);
return PR_FALSE;
break;
}
return PR_FALSE;
}
PRBool
bs_connection_set_uint_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bsuint v)
{
return bs_connection_set_property (connection, prop, BSTYPE_UINT, &v);
}
PRBool
bs_connection_set_string_property (BSConnectionClass *connection,
BSConnectionProperty prop,
char *v)
{
return bs_connection_set_property (connection, prop, BSTYPE_STRING, v);
}
PRBool
bs_connection_set_bool_property (BSConnectionClass *connection,
BSConnectionProperty prop,
PRBool v)
{
return bs_connection_set_property (connection, prop, BSTYPE_BOOLEAN, &v);
}
PRBool
bs_connection_set_object_property (BSConnectionClass *connection,
BSConnectionProperty prop,
void *v)
{
return bs_connection_set_property (connection, prop, BSTYPE_OBJECT, v);
}
PRBool
bs_connection_get_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bsint type, void *v)
{
PR_ASSERT (connection);
switch (prop)
{
case BSPROP_PARENT:
if (!BS_CHECK_TYPE (type, BSTYPE_OBJECT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
v = connection->parent_server;
break;
case BSPROP_LINE_BUFFER:
if (!BS_CHECK_TYPE (type, BSTYPE_BOOLEAN))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(PRBool *)v = connection->linebuffer_flag;
break;
case BSPROP_PORT:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(int *)v = connection->port;
break;
case BSPROP_STATUS:
if (!BS_CHECK_TYPE (type, BSTYPE_BOOLEAN))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(PRBool *)v = connection->is_connected;
break;
default:
BS_ReportError (BSERR_NO_SUCH_PARAM);
return PR_FALSE;
break;
}
return PR_TRUE;
}
PRBool
bs_connection_get_uint_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bsuint *v)
{
return bs_connection_get_property (connection, prop, BSTYPE_UINT, v);
}
PRBool
bs_connection_get_string_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bschar **v)
{
return bs_connection_get_property (connection, prop, BSTYPE_STRING, v);
}
PRBool
bs_connection_get_bool_property (BSConnectionClass *connection,
BSConnectionProperty prop,
PRBool *v)
{
return bs_connection_get_property (connection, prop, BSTYPE_BOOLEAN, v);
}
PRBool
bs_connection_get_object_property (BSConnectionClass *connection,
BSConnectionProperty prop,
void **v)
{
return bs_connection_get_property (connection, prop, BSTYPE_OBJECT, v);
}
PR_END_EXTERN_C

View File

@ -1,135 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsconnection_h___
#define bsconnection_h___
#include "prtypes.h"
#include "prio.h"
#include "bspubtd.h"
#include "bsqueue.h"
#include "bsevent.h"
PR_BEGIN_EXTERN_C
/* constructor, should be called only by a friend's factory */
extern BSConnectionClass *
bs_connection_new (BSServerClass *parent, PRFileDesc *fd, bsint port);
/* deallocator, should be called only by a friend's factory */
extern void
bs_connection_free (BSConnectionClass *connection);
/* restablish the connection */
extern PRBool
bs_connection_reconnect (BSConnectionClass *connection);
/* close the connection */
extern PRBool
bs_connection_disconnect (BSConnectionClass *connection);
/* send an arbitrary number of bytes */
extern PRBool
bs_connection_send_data (BSConnectionClass *connection, bschar *data,
bsuint length);
/* send a null-terminated string */
extern PRBool
bs_connection_send_string (BSConnectionClass *connection, const bschar *data);
PRBool /* friend function */
bs_connection_recv_data (BSConnectionClass *connection, PRInt32 timeout,
bschar **buf);
/*
* recv data from the connection. This is a friend function, non-friends
* should subscribe to BSEVENT_SERVER_RAWDATA or BSEVENT_CONNECTION_RAWDATA.
* The friendly factory which created the connection is responsible for
* periodically calling this function, or the RAWDATA event will never occur.
*/
extern PRBool
bs_connection_recv (BSConnectionClass *connection, BSQueueClass *event_queue);
/* retrieve connections fd, friend function */
extern PRFileDesc *
bs_connection_get_fd (BSConnectionClass *connection);
/* route an event, friends only */
BSEventClass *
bs_connection_route (BSConnectionClass *connection, BSEventClass *event);
/* changes an event handler */
extern PRBool
bs_connection_set_handler (BSConnectionClass *connection,
BSConnectionEvent event_type,
BSConnectionEventCallback *handler);
/* property access routines */
extern PRBool
bs_connection_set_uint_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bsuint v);
extern PRBool
bs_connection_set_string_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bschar *v);
extern PRBool
bs_connection_set_bool_property (BSConnectionClass *connection,
BSConnectionProperty prop,
PRBool v);
extern PRBool
bs_connection_set_object_property (BSConnectionClass *connection,
BSConnectionProperty prop,
void *v);
/* property gets */
extern PRBool
bs_connection_get_uint_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bsuint *v);
extern PRBool
bs_connection_get_string_property (BSConnectionClass *connection,
BSConnectionProperty prop,
bschar **v);
extern PRBool
bs_connection_get_bool_property (BSConnectionClass *connection,
BSConnectionProperty prop,
PRBool *v);
extern PRBool
bs_connection_get_object_property (BSConnectionClass *connection,
BSConnectionProperty prop,
void **v);
PR_END_EXTERN_C
#endif /* bsconnection_h___ */

View File

@ -1,96 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#include <stdio.h>
#include "prerror.h"
#include "prmem.h"
#include "prlog.h"
#include "bspubtd.h"
#include "bserror.h"
const char *bs_errormsg_map[BSERR_MAP_SIZE] = {
"Undefined Error",
"Out of memory",
"Parameter mismatch",
"Property not supported",
"Connect timed out",
"Property is Read-Only",
"Invalid State"
};
void
BS_ReportError (bsint err)
{
fprintf (stderr, "BS Error (%i): %s\n", err, bs_errormsg_map[err]);
#ifdef DEBUG
if (err == BSERR_OUT_OF_MEMORY)
PR_ASSERT (PR_FALSE);
#endif
}
void
BS_ReportPRError (bsint err)
{
const char *name;
const char *msg;
name = PR_ErrorToName (err);
msg = PR_ErrorToString (err, 0);
fprintf (stderr, "NSPR Error (%i/%s): %s\n", err, name, msg);
}
void
BS_old_ReportPRError (bsint err)
{
char *msg;
bsuint c;
c = PR_GetErrorTextLength();
if (!c)
{
fprintf (stderr, "Unknown NSPR Error (%i)\n", err);
return;
}
msg = PR_Malloc (c * (sizeof (bschar *) + 1));
if (!msg)
{
fprintf (stderr, "Out of Memory while reporting NSPR error %i\n", err);
return;
}
PR_GetErrorText (msg);
fprintf (stderr, "NSPR Error (%i): %s\n", err, msg);
PR_Free (msg);
}

View File

@ -1,56 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bserror_h___
#define bserror_h___
#include "prerror.h"
#include "bspubtd.h"
PR_BEGIN_EXTERN_C
/* error codes */
#define BSERR_UNDEFINED_ERROR 0
#define BSERR_OUT_OF_MEMORY 1
#define BSERR_PROPERTY_MISMATCH 2
#define BSERR_NO_SUCH_PARAM 3
#define BSERR_NO_SUCH_EVENT 4
#define BSERR_CONNECTION_TIMEOUT 5
#define BSERR_READ_ONLY 6
#define BSERR_INVALID_STATE 7
#define BSERR_MAP_SIZE 7
#define OUT_OF_MEMORY BS_ReportError (BSERR_OUT_OF_MEMORY);
PR_EXTERN (void)
BS_ReportError (bsint err);
PR_EXTERN (void)
BS_ReportPRError (PRErrorCode err);
PR_END_EXTERN_C
#endif /* bserror_h___ */

View File

@ -1,347 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#include "prtypes.h"
#include "prmem.h"
#include "prlog.h"
#include "bsapi.h"
#include "bspubtd.h"
#include "bserror.h"
#include "bsevent.h"
#include "bsnetwork.h"
#include "bsserver.h"
#include "bsconnection.h"
PR_BEGIN_EXTERN_C
BSEventClass *
bs_event_new (BSObjectType obj_type, void *dest, BSHandlerID id, void *data,
BSEventClass *previous, BSEventDeallocator *da)
{
BSEventClass *new_event;
new_event = PR_NEW (BSEventClass);
if (!new_event)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return NULL;
}
new_event->obj_type = obj_type;
new_event->dest = dest;
new_event->id = id;
new_event->data = data;
new_event->previous = previous;
new_event->da = da;
return new_event;
}
void *
bs_event_default_deallocator (BSEventClass *event)
{
PR_ASSERT (event);
PR_FREEIF (event->data);
return NULL;
}
BSEventClass *
bs_event_new_copy (BSObjectType obj_type, void *dest, BSHandlerID id,
void *data, bsuint length, BSEventClass *previous)
{
BSEventClass *rv;
char *event_data;
event_data = PR_Malloc (length);
if (!event_data)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return NULL;
}
memcpy (event_data, data, length);
rv = bs_event_new (obj_type, dest, id, event_data, previous,
bs_event_default_deallocator);
if (!rv)
return NULL;
return rv;
}
BSEventClass *
bs_event_new_copyZ (BSObjectType obj_type, void *dest, BSHandlerID id,
bschar *data, BSEventClass *previous)
{
return bs_event_new_copy (obj_type, dest, id, data, strlen (data) + 1,
previous);
}
void
bs_event_free (BSEventClass *event)
{
PR_ASSERT (event);
if (event->previous)
bs_event_free (event->previous);
if (event->da)
event->da (event);
PR_Free (event);
}
PRBool
bs_event_route (BSEventClass *event, BSEventHookCallback *hook_func)
{
BSEventClass *next_event;
PR_ASSERT (event);
if ((hook_func) && (!hook_func (event)))
return PR_TRUE;
switch (event->obj_type)
{
case BSOBJ_NETWORK:
next_event = bs_network_route ((BSNetworkClass *)event->dest,
event);
break;
case BSOBJ_SERVER:
next_event = bs_server_route ((BSServerClass *)event->dest,
event);
break;
case BSOBJ_CONNECTION:
next_event = bs_connection_route ((BSConnectionClass *)event->dest,
event);
break;
default:
BS_ReportError (BSERR_INVALID_STATE);
return PR_FALSE;
break;
}
if (next_event)
{
next_event->previous = event;
bs_event_route (next_event, hook_func);
}
return PR_TRUE;
}
PRBool
bs_event_set_property (BSEventClass *event, BSEventProperty prop, bsint type,
void *v)
{
PR_ASSERT (event);
switch (prop)
{
case BSPROP_OBJECT_TYPE:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
if ((BSObjectType)v >= BSOBJ_INVALID_OBJECT)
{
BS_ReportError (BSERR_INVALID_STATE);
return PR_FALSE;
}
event->obj_type = *(BSObjectType *)v;
break;
case BSPROP_DESTOBJECT:
if (!BS_CHECK_TYPE (type, BSTYPE_OBJECT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
event->dest = (void *)v;
break;
case BSPROP_HANDLER_ID:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
event->id = *(BSHandlerID *)v;
break;
case BSPROP_DATA:
BS_ReportError (BSERR_READ_ONLY);
return PR_FALSE;
break;
default:
BS_ReportError (BSERR_NO_SUCH_PARAM);
return PR_FALSE;
break;
}
return PR_FALSE;
}
PRBool
bs_event_set_uint_property (BSEventClass *event, BSEventProperty prop,
bsuint v)
{
return bs_event_set_property (event, prop, BSTYPE_UINT, &v);
}
PRBool
bs_event_set_string_property (BSEventClass *event, BSEventProperty prop,
char *v)
{
return bs_event_set_property (event, prop, BSTYPE_STRING, v);
}
PRBool
bs_event_set_bool_property (BSEventClass *event, BSEventProperty prop,
PRBool v)
{
return bs_event_set_property (event, prop, BSTYPE_BOOLEAN, &v);
}
PRBool
bs_event_set_object_property (BSEventClass *event, BSEventProperty prop,
void *v)
{
return bs_event_set_property (event, prop, BSTYPE_OBJECT, v);
}
PRBool
bs_event_get_property (BSEventClass *event, BSEventProperty prop, bsint type,
void *v)
{
PR_ASSERT (event);
switch (prop)
{
case BSPROP_OBJECT_TYPE:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(BSObjectType *)v = event->obj_type;
break;
case BSPROP_DESTOBJECT:
if (!BS_CHECK_TYPE (type, BSTYPE_OBJECT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(void **)v = event->dest;
break;
case BSPROP_HANDLER_ID:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(BSHandlerID *)v = event->id;
break;
case BSPROP_DATA:
*(void **)v = event->data;
break;
default:
BS_ReportError (BSERR_NO_SUCH_PARAM);
return PR_FALSE;
break;
}
return PR_TRUE;
}
PRBool
bs_event_get_uint_property (BSEventClass *event, BSEventProperty prop,
bsuint *v)
{
return bs_event_set_property (event, prop, BSTYPE_UINT, v);
}
PRBool
bs_event_get_string_property (BSEventClass *event, BSEventProperty prop,
bschar **v)
{
return bs_event_set_property (event, prop, BSTYPE_STRING, v);
}
PRBool
bs_event_get_bool_property (BSEventClass *event, BSEventProperty prop,
PRBool *v)
{
return bs_event_set_property (event, prop, BSTYPE_BOOLEAN, v);
}
PRBool
bs_event_get_object_property (BSEventClass *event, BSEventProperty prop,
void **v)
{
return bs_event_set_property (event, prop, BSTYPE_OBJECT, v);
}
PR_END_EXTERN_C

View File

@ -1,64 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsevent_h___
#define bsevent_h___
#include "prtypes.h"
PR_BEGIN_EXTERN_C
/* constructor */
extern BSEventClass *
bs_event_new (BSObjectType obj_type, void *dest, BSHandlerID id, void *data,
BSEventClass *previous, BSEventDeallocator *da);
/*
* alternate constructor. makes a memcpy of *data, and automatically
* frees it in bs_event_free
*/
extern BSEventClass *
bs_event_new_copy (BSObjectType obj_type, void *dest, BSHandlerID id,
void *data, bsuint length, BSEventClass *previous);
/*
* alternate constructor. makes a copy of the null terminated string in
* *data, and automatically frees it in bs_event_free
*/
extern BSEventClass *
bs_event_new_copyZ (BSObjectType obj_type, void *dest, BSHandlerID id,
bschar *data, BSEventClass *previous);
/* deallocator */
extern void
bs_event_free (BSEventClass *event);
extern PRBool
bs_event_route (BSEventClass *event, BSEventHookCallback *hook_func);
PR_END_EXTERN_C
#endif /* bsevent_h___ */

View File

@ -1,375 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#include "prtypes.h"
#include "prmem.h"
#include "prlog.h"
#include "bsapi.h"
#include "bsconfig.h"
#include "bspubtd.h"
#include "bserror.h"
#include "bsserver.h"
#include "bsconnection.h"
PR_BEGIN_EXTERN_C
typedef struct BSServerLink BSServerLink;
struct BSServerLink {
PRCList list;
BSServerClass *server;
};
typedef struct BSServerList BSServerList;
BSNetworkClass *
bs_network_new (const char *name)
{
BSNetworkClass *new_network;
new_network = PR_NEW (BSNetworkClass);
if (!new_network)
return PR_FALSE;
new_network->name = PR_Malloc ((strlen (name) + 1) *
sizeof (bschar));
if (!new_network->name)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
strcpy (new_network->name, name);
new_network->event_queue = bs_queue_new();
if (!new_network->event_queue)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return NULL;
}
new_network->events_per_step = BS_EVENTS_PER_STEP_DEFAULT;
new_network->server_count = 0;
PR_INIT_CLIST (&new_network->server_list);
return new_network;
}
void
bs_network_free (BSNetworkClass *network)
{
PRCList *head;
BSServerClass *server;
PR_ASSERT (network);
while (bs_queue_size (network->event_queue) > 0)
bs_queue_pop (network->event_queue, NULL);
bs_queue_free (network->event_queue);
while (!PR_CLIST_IS_EMPTY(&network->server_list))
{
head = PR_LIST_HEAD(&network->server_list);
if (head == &network->server_list)
break;
server = ((BSServerLink *)head)->server;
bs_server_free (server);
PR_REMOVE_AND_INIT_LINK(head);
network->server_count--;
}
PR_ASSERT (network->server_count == 0);
PR_FREEIF (server->hostname);
PR_Free (server);
}
BSServerClass *
bs_network_add_server (BSNetworkClass *network, const char *hostname)
{
BSServerLink *server_link;
server_link = PR_NEW(BSServerLink);
if (!server_link)
return NULL;
server_link->server = bs_server_new (network, hostname);
if (!server_link->server)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return NULL;
}
PR_APPEND_LINK ((PRCList *)server_link, &network->server_list);
network->server_count++;
return server_link->server;
}
PRBool
bs_network_enumerate_servers (BSNetworkClass *network,
BSEnumerateCallback *enum_func, void *data)
{
PRCList *link;
BSServerClass *server;
bsuint i = 0;
PR_ASSERT (network);
if (PR_CLIST_IS_EMPTY(&network->server_list))
return PR_TRUE;
link = PR_LIST_HEAD(&network->server_list);
while (link != (PRCList *)network)
{
server = ((BSServerLink *)link)->server;
if (!enum_func (server, data, i++))
break;
link = PR_NEXT_LINK (link);
}
return PR_TRUE;
}
PRBool
bs_network_server_enumerator (void *server, void *event_queue,
bsuint i)
{
bs_server_poll_connections ((BSServerClass *)server,
(BSQueueClass *)event_queue);
return PR_TRUE;
}
PRBool
bs_network_poll_servers (BSNetworkClass *network)
{
bs_network_enumerate_servers (network, bs_network_server_enumerator,
network->event_queue);
return PR_TRUE;
}
BSEventClass *
bs_network_route (BSNetworkClass *network, BSEventClass *event)
{
if ((event->id < BSNETWORK_EVENT_COUNT) &&
(network->callback_table[event->id]))
return network->callback_table[event->id](network, event);
else
return NULL;
}
void
bs_network_step_events (BSNetworkClass *network, bsuint *event_count)
{
bsuint i;
BSEventClass *event;
if (event_count)
*event_count = 0;
for (i = 0; (i < network->events_per_step) &&
(bs_queue_size (network->event_queue) > 0); i++)
{
event = bs_queue_pop (network->event_queue, NULL);
bs_event_route (event, NULL);
if (event_count)
(*event_count)++;
}
}
PRBool
bs_network_set_handler (BSNetworkClass *network, BSNetworkEvent event_type,
BSNetworkEventCallback *handler)
{
PR_ASSERT (network);
network->callback_table[event_type] = handler;
return PR_TRUE;
}
PRBool
bs_network_set_property (BSNetworkClass *network, BSNetworkProperty prop,
bsint type, void *v)
{
PR_ASSERT (network);
switch (prop)
{
case BSPROP_NAME:
if (!BS_CHECK_TYPE (type, BSTYPE_STRING))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
BS_ReportError (BSERR_READ_ONLY);
return PR_FALSE;
break;
case BSPROP_EVENTS_PER_STEP:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
network->events_per_step = *(bsint *)v;
break;
default:
break;
}
return PR_TRUE;
}
PRBool
bs_network_set_uint_property (BSNetworkClass *network, BSNetworkProperty prop,
bsuint v)
{
return bs_network_set_property (network, prop, BSTYPE_UINT, &v);
}
PRBool
bs_network_set_string_property (BSNetworkClass *network,
BSNetworkProperty prop, bschar *v)
{
return bs_network_set_property (network, prop, BSTYPE_STRING, v);
}
PRBool
bs_network_set_bool_property (BSNetworkClass *network, BSNetworkProperty prop,
PRBool v)
{
return bs_network_set_property (network, prop, BSTYPE_BOOLEAN, &v);
}
PRBool
bs_network_set_object_property (BSNetworkClass *network,
BSNetworkProperty prop, void *v)
{
return bs_network_set_property (network, prop, BSTYPE_OBJECT, v);
}
PRBool
bs_network_get_property (BSNetworkClass *network, BSServerProperty prop,
bsint type, void **v)
{
PR_ASSERT (network);
switch (prop)
{
case BSPROP_NAME:
if (!BS_CHECK_TYPE (type, BSTYPE_STRING))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(bschar **)v = network->name;
break;
case BSPROP_EVENTS_PER_STEP:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(bsint *)v = network->events_per_step;
break;
default:
break;
}
return PR_TRUE;
}
PRBool
bs_network_get_uint_property (BSNetworkClass *network, BSNetworkProperty prop,
bsuint *v)
{
return bs_network_set_property (network, prop, BSTYPE_UINT, v);
}
PRBool
bs_network_get_string_property (BSNetworkClass *network,
BSNetworkProperty prop, bschar **v)
{
return bs_network_set_property (network, prop, BSTYPE_STRING, v);
}
PRBool
bs_network_get_bool_property (BSNetworkClass *network, BSNetworkProperty prop,
PRBool *v)
{
return bs_network_set_property (network, prop, BSTYPE_BOOLEAN, v);
}
PRBool
bs_network_get_object_property (BSNetworkClass *network,
BSNetworkProperty prop, BSNetworkClass **v)
{
return bs_network_set_property (network, prop, BSTYPE_OBJECT, v);
}
PR_END_EXTERN_C

View File

@ -1,95 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsnetwork_h___
#define bsnetwork_h___
#include "prtypes.h"
#include "bspubtd.h"
#include "bsserver.h"
#include "bsconnection.h"
PR_BEGIN_EXTERN_C
extern BSNetworkClass *
bs_network_new (const char *name);
extern void
bs_network_free (BSNetworkClass *network);
BSServerClass *
bs_network_add_server (BSNetworkClass *network, const char *hostname);
PRBool
bs_network_poll_servers (BSNetworkClass *network);
BSEventClass *
bs_network_route (BSNetworkClass *network, BSEventClass *event);
extern void
bs_network_step_events (BSNetworkClass *network, bsuint *event_count);
extern PRBool
bs_connection_set_handler (BSConnectionClass *connection,
BSConnectionEvent event_type,
BSConnectionEventCallback *handler);
extern PRBool
bs_network_set_uint_property (BSNetworkClass *network, BSNetworkProperty prop,
bsuint v);
extern PRBool
bs_network_set_string_property (BSNetworkClass *network,
BSNetworkProperty prop, bschar *v);
extern PRBool
bs_network_set_bool_property (BSNetworkClass *network, BSNetworkProperty prop,
PRBool v);
extern PRBool
bs_network_set_object_property (BSNetworkClass *network,
BSNetworkProperty prop, void *v);
extern PRBool
bs_network_get_uint_property (BSNetworkClass *network, BSNetworkProperty prop,
bsuint *v);
extern PRBool
bs_network_get_string_property (BSNetworkClass *network,
BSNetworkProperty prop, bschar **v);
extern PRBool
bs_network_get_bool_property (BSNetworkClass *network,
BSNetworkProperty prop, PRBool *v);
extern PRBool
bs_network_get_object_property (BSNetworkClass *network,
BSNetworkProperty prop, BSNetworkClass **v);
PR_END_EXTERN_C
#endif /* bsnetwork_h__ */

View File

@ -1,148 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bspubtd_h___
#define bspubtd_h___
#include "prtypes.h"
#include "prclist.h"
#include "prio.h"
PR_BEGIN_EXTERN_C
typedef PRInt32 bsint;
typedef PRUint16 bsuint;
typedef PRInt64 bsdouble;
typedef char bschar;
typedef bsint BSHandlerID;
typedef bsuint BSNetworkProperty;
typedef bsuint BSServerProperty;
typedef bsuint BSConnectionProperty;
typedef bsuint BSEventProperty;
typedef struct BSQueueClass BSQueueClass;
typedef struct BSEventClass BSEventClass;
typedef struct BSNetworkClass BSNetworkClass;
typedef struct BSServerClass BSServerClass;
typedef struct BSConnectionClass BSConnectionClass;
typedef BSEventClass *BSEventHookCallback (BSEventClass *event);
typedef BSEventClass *BSNetworkEventCallback (BSNetworkClass *network,
BSEventClass *event);
typedef BSEventClass *BSServerEventCallback (BSServerClass *server,
BSEventClass *event);
typedef BSEventClass *BSConnectionEventCallback (BSConnectionClass *connection,
BSEventClass *event);
typedef PRBool BSEnumerateCallback (void *obj, void *data, bsuint i);
typedef void *BSEventDeallocator (BSEventClass *event);
typedef enum BSType {
BSTYPE_UINT = 1,
BSTYPE_STRING = 2,
BSTYPE_BOOLEAN = 4,
BSTYPE_OBJECT = 8
} BSType;
typedef enum BSObjectType {
BSOBJ_NETWORK,
BSOBJ_SERVER,
BSOBJ_CONNECTION,
BSOBJ_INVALID_OBJECT
} BSObjectType;
struct BSEventClass {
BSEventDeallocator *da;
BSObjectType obj_type;
BSEventClass *previous;
BSHandlerID id;
void *dest;
void *data;
};
/** network typedefs **/
typedef enum BSNetworkEvent {
BSEVENT_NETWORK_HOOK_CALLBACK,
BSNETWORK_EVENT_COUNT
} BSNetworkEvent;
struct BSNetworkClass
{
PRCList server_list;
BSNetworkEventCallback *callback_table[BSNETWORK_EVENT_COUNT];
bschar *name;
BSQueueClass *event_queue;
bsuint events_per_step, server_count;
};
/** server typedefs **/
typedef enum BSServerEvent {
BSEVENT_SERVER_HOOK_CALLBACK,
BSEVENT_SERVER_CONNECT,
BSEVENT_SERVER_DISCONNECT,
BSEVENT_SERVER_RAWDATA,
BSSERVER_EVENT_COUNT
} BSServerEvent;
struct BSServerClass
{
PRCList connection_list;
BSServerEventCallback *callback_table[BSSERVER_EVENT_COUNT];
BSNetworkClass *parent_network;
bschar *hostname;
bsuint input_timeout, connection_count;
PRBool linebuffer_flag;
};
/** connection typedefs **/
typedef enum BSConnectionEvent {
BSEVENT_CONNECTION_HOOK_CALLBACK,
BSEVENT_CONNECTION_CONNECT,
BSEVENT_CONNECTION_DISCONNECT,
BSEVENT_CONNECTION_RAWDATA,
BSCONNECTION_EVENT_COUNT
} BSConnectionEvent;
struct BSConnectionClass
{
BSConnectionEventCallback *callback_table[BSCONNECTION_EVENT_COUNT];
BSServerClass *parent_server;
PRBool linebuffer_flag, is_connected;
bsint port;
bschar *linebuffer;
PRFileDesc *fd;
};
PR_END_EXTERN_C
#endif /* bspubtd_h___ */

View File

@ -1,236 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#include "prtypes.h"
#include "prmem.h"
#include "prlog.h"
#include "bsqueue.h"
#include "bspubtd.h"
typedef int QueueCompareOp (void *, void *);
typedef struct BSQueueElementClass BSQueueElementClass;
struct BSQueueElementClass {
void *data;
cron_t cron; /* elements will be sorted in cron order */
BSQueueElementClass *up;
};
struct BSQueueClass {
bsuint size;
BSQueueElementClass *bottom; /* queue pulls from the bottom up */
QueueCompareOp *CompareOp;
};
BSQueueClass*
bs_queue_new (void)
{
BSQueueClass *newqueue;
newqueue = PR_NEW (BSQueueClass);
newqueue->bottom = NULL;
newqueue->size = 0;
return newqueue;
}
void
bs_queue_free (BSQueueClass *queue)
{
PR_ASSERT (queue->size == 0);
PR_ASSERT (queue->bottom == NULL);
PR_Free (queue);
queue = NULL;
}
int
bs_queue_add (BSQueueClass *queue, void *data, cron_t cron)
{
BSQueueElementClass *newelement, *currentelement, *previouselement = NULL;
PR_ASSERT (queue);
newelement = PR_NEW (BSQueueElementClass);
if (!newelement)
return 0;
newelement->up = NULL;
newelement->data = data;
newelement->cron = cron;
if (queue->bottom == NULL) /* if the queue is empty */
{
queue->bottom = newelement; /* then this is the first element */
queue->size = 1;
}
else /* otherwise */
{
currentelement = queue->bottom; /* search for the right spot */
/* find the first element with a smaller cron than this element */
while (currentelement && (newelement->cron >= currentelement->cron))
{
previouselement = currentelement;
currentelement = currentelement->up;
}
if (currentelement) /* if we're not left at the top of the queue */
{
if (previouselement) /* were either in the middle, */
{
newelement->up = currentelement; /* insert the new element */
previouselement->up = newelement; /* above the current one */
}
else /* or at the bottom */
{
newelement->up = queue->bottom;
queue->bottom = newelement;
}
}
else /* otherwise */
{
previouselement->up = newelement; /* this is the new top element */
}
queue->size++;
}
return queue->size;
}
void *
bs_queue_pop (BSQueueClass *queue, cron_t *cron)
{
BSQueueElementClass *bottomelement;
void *rval;
PR_ASSERT (queue);
if (queue->size < 1)
return NULL;
bottomelement = queue->bottom;
if (cron)
*cron = queue->bottom->cron;
rval = bottomelement->data;
queue->bottom = bottomelement->up;
queue->size--;
if (queue->size < 1)
{
queue->bottom = NULL;
}
PR_Free (bottomelement);
return rval;
}
void *
bs_queue_peek (BSQueueClass *queue, cron_t *cron)
{
PR_ASSERT (queue);
if (queue->size < 1)
return NULL;
if (cron)
*cron = queue->bottom->cron;
return (queue->bottom->data);
}
int
bs_queue_size (BSQueueClass *queue)
{
PR_ASSERT (queue);
return queue->size;
}
/* deletes all queue items which have the data *data */
int
bs_queue_delete (BSQueueClass *queue, void *data)
{
BSQueueElementClass *currentelement, *lastelement;
if (!(currentelement = queue->bottom))
return 0;
/* move the bottom up */
while (queue->bottom->data == data)
{
lastelement = queue->bottom;
queue->bottom = queue->bottom->up;
queue->size--;
PR_Free (lastelement);
currentelement = queue->bottom;
}
/* then trim the middle */
while (currentelement->up)
{
if (currentelement->up->data == data)
{
currentelement->up = currentelement->up->up;
lastelement = currentelement->up;
queue->size--;
PR_Free (lastelement);
}
currentelement = currentelement->up;
}
return 1;
}

View File

@ -1,57 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsqueue_h___
#define bsqueue_h___
#include "prtypes.h"
#include "bspubtd.h"
PR_BEGIN_EXTERN_C
typedef PRUint32 cron_t;
BSQueueClass *
bs_queue_new (void);
void
bs_queue_free (BSQueueClass *queue);
int
bs_queue_add (BSQueueClass *queue, void *data, cron_t cron);
void *
bs_queue_pop (BSQueueClass *queue, cron_t *cron);
void *
bs_queue_peek (BSQueueClass *queue, cron_t *cron);
int
bs_queue_size (BSQueueClass *queue);
PR_END_EXTERN_C
#endif /* bsqueue_h___ */

View File

@ -1,513 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#include <string.h>
#include "prtypes.h"
#include "prmem.h"
#include "prio.h"
#include "prclist.h"
#include "prlog.h"
#include "prnetdb.h"
#include "bspubtd.h"
#include "bsconfig.h"
#include "bserror.h"
#include "bsevent.h"
#include "bsapi.h"
#include "bsconnection.h"
#include "bsserver.h"
#include "bsutil.h"
PR_BEGIN_EXTERN_C
typedef struct BSConnectionEnumData BSConnectionEnumData;
typedef struct BSConnectionLink BSConnectionLink;
struct BSConnectionEnumData {
PRPollDesc *polldesc;
BSConnectionClass **connection;
};
struct BSConnectionLink {
PRCList list;
BSConnectionClass *connection;
};
BSServerClass *
bs_server_new (BSNetworkClass *parent, const char *hostname)
{
BSServerClass *new_server;
new_server = PR_NEW (BSServerClass);
if (!new_server)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
if (!hostname)
{
BS_ReportError (BSERR_INVALID_STATE);
PR_Free (new_server);
return NULL;
}
new_server->hostname = PR_Malloc ((strlen (hostname) + 1) *
sizeof (bschar));
if (!new_server->hostname)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
PR_Free (new_server);
return PR_FALSE;
}
strcpy (new_server->hostname, hostname);
memset (new_server->callback_table, 0,
BSSERVER_EVENT_COUNT);
new_server->parent_network = parent;
new_server->connection_count = 0;
new_server->input_timeout = BS_INPUT_TIMEOUT_DEFAULT;
PR_INIT_CLIST (&new_server->connection_list);
return new_server;
}
void
bs_server_free (BSServerClass *server)
{
PRCList *head;
BSConnectionClass *connection;
PR_ASSERT (server);
while (!PR_CLIST_IS_EMPTY(&server->connection_list))
{
head = PR_LIST_HEAD(&server->connection_list);
if (head == &server->connection_list)
break;
connection = ((BSConnectionLink *)head)->connection;
bs_connection_free (connection);
PR_REMOVE_AND_INIT_LINK(head);
server->connection_count--;
}
PR_ASSERT (server->connection_count == 0);
if (server->hostname)
PR_Free (server->hostname);
PR_Free (server);
}
BSConnectionClass *
bs_server_connect (BSServerClass *server, bsint port, const bschar *bind_addr,
PRBool tcp)
{
PRFileDesc *fd;
PRNetAddr naconnect, nabind;
PRIntervalTime to;
PRStatus rv;
BSConnectionClass *connection;
BSConnectionLink *connection_link;
PR_ASSERT (server);
if (tcp)
fd = PR_NewTCPSocket();
else
fd = PR_NewUDPSocket();
if (!fd)
{
BS_ReportPRError (PR_GetError());
return NULL;
}
if (bs_util_is_ip (server->hostname))
rv = PR_StringToNetAddr (server->hostname, &naconnect);
else
rv = bs_util_resolve_host (server->hostname, &naconnect);
if (PR_FAILURE == rv)
{
BS_ReportPRError (PR_GetError());
goto error_out;
}
if (bind_addr)
{
rv = PR_StringToNetAddr (bind_addr, &nabind);
if (PR_FAILURE == rv)
{
BS_ReportPRError (PR_GetError());
goto error_out;
}
PR_Bind (fd, &nabind);
}
rv = PR_InitializeNetAddr (PR_IpAddrNull, port, &naconnect);
if (PR_FAILURE == rv)
{
BS_ReportPRError (PR_GetError());
goto error_out;
}
to = PR_MillisecondsToInterval (BS_CONNECTION_TIMEOUT_MS);
rv = PR_Connect (fd, &naconnect, to);
if (PR_FAILURE == rv)
{
BS_ReportPRError (PR_GetError());
goto error_out;
}
connection = bs_connection_new (server, fd, port);
if (connection)
{
connection_link = PR_NEW (BSConnectionLink);
if (!connection_link)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
PR_Shutdown (fd, PR_SHUTDOWN_BOTH);
goto error_out;
}
connection_link->connection = connection;
PR_APPEND_LINK ((PRCList *)connection_link, &server->connection_list);
}
server->connection_count++;
return connection;
error_out:
PR_Close (fd);
return NULL;
}
PRBool
bs_server_enumerate_connections (BSServerClass *server,
BSEnumerateCallback *enum_func, void *data)
{
PRCList *link;
BSConnectionClass *connection;
bsuint i = 0;
PR_ASSERT (server);
if (PR_CLIST_IS_EMPTY(&server->connection_list))
return PR_TRUE;
link = PR_LIST_HEAD(&server->connection_list);
while (link != (PRCList *)server)
{
connection = ((BSConnectionLink *)link)->connection;
if (!enum_func (connection, data, i++))
break;
link = PR_NEXT_LINK (link);
}
return PR_TRUE;
}
PRBool
bs_server_connection_enumerator (void *connection,
void *enumdata, bsuint i)
{
PRFileDesc *fd;
BSConnectionEnumData *ed;
fd = bs_connection_get_fd ((BSConnectionClass *)connection);
ed = (BSConnectionEnumData *)enumdata;
ed->polldesc[i].fd = fd;
ed->polldesc[i].in_flags = PR_POLL_READ;
ed->connection[i] = (BSConnectionClass *)connection;
return PR_TRUE;
}
PRBool
bs_server_poll_connections (BSServerClass *server, BSQueueClass *event_queue)
{
PRInt32 rv, i;
BSConnectionEnumData enumdata;
enumdata.polldesc = PR_Calloc (server->connection_count,
sizeof (PRPollDesc *));
enumdata.connection = PR_Calloc (server->connection_count,
sizeof (BSConnectionClass *));
if (!enumdata.polldesc || !enumdata.connection)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
bs_server_enumerate_connections (server, bs_server_connection_enumerator,
&enumdata);
rv = PR_Poll (enumdata.polldesc, server->connection_count,
PR_INTERVAL_NO_WAIT);
for (i = 0; i < server->connection_count; i++)
if (enumdata.polldesc[i].out_flags & PR_POLL_READ)
bs_connection_recv (enumdata.connection[i], event_queue);
return PR_TRUE;
}
BSEventClass *
bs_server_route (BSServerClass *server, BSEventClass *event)
{
if ((event->id < BSSERVER_EVENT_COUNT) &&
(server->callback_table[event->id]))
return server->callback_table[event->id](server, event);
else
return NULL;
}
PRBool
bs_server_set_handler (BSServerClass *server, BSServerEvent event_type,
BSServerEventCallback *handler)
{
PR_ASSERT (server);
if (event_type > BSSERVER_EVENT_COUNT)
{
BS_ReportError (BSERR_NO_SUCH_EVENT);
return PR_FALSE;
}
server->callback_table[event_type] = handler;
return PR_TRUE;
}
PRBool
bs_server_set_property (BSServerClass *server, BSServerProperty prop,
bsint type, void *v)
{
PR_ASSERT (server);
switch (prop)
{
case BSPROP_PARENT:
if (!BS_CHECK_TYPE(type, BSTYPE_OBJECT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
server->parent_network = (BSNetworkClass *)v;
break;
case BSPROP_INPUT_TIMEOUT:
if (!BS_CHECK_TYPE(type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
server->input_timeout = *(int *)v;
break;
case BSPROP_LINE_BUFFER:
if (!BS_CHECK_TYPE(type, BSTYPE_BOOLEAN))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
server->linebuffer_flag = *(PRBool *)v;
break;
case BSPROP_HOSTNAME:
if (!BS_CHECK_TYPE(type, BSTYPE_STRING))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
PR_FREEIF (server->hostname);
server->hostname = PR_Malloc ((strlen ((bschar *)v) + 1) *
sizeof (bschar));
if (!server->hostname)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return PR_FALSE;
}
strcpy (server->hostname, (bschar *)v);
break;
default:
break;
}
return PR_FALSE;
}
PRBool
bs_server_set_uint_property (BSServerClass *server, BSServerProperty prop,
bsuint *v)
{
return bs_server_set_property (server, prop, BSTYPE_UINT, &v);
}
PRBool
bs_server_set_string_property (BSServerClass *server, BSServerProperty prop,
bschar *v)
{
return bs_server_set_property (server, prop, BSTYPE_STRING, v);
}
PRBool
bs_server_set_bool_property (BSServerClass *server, BSServerProperty prop,
PRBool *v)
{
return bs_server_set_property (server, prop, BSTYPE_BOOLEAN, &v);
}
PRBool
bs_server_set_object_property (BSServerClass *server, BSServerProperty prop,
void *v)
{
return bs_server_set_property (server, prop, BSTYPE_OBJECT, v);
}
PRBool
bs_server_get_property (BSServerClass *server, BSServerProperty prop,
bsint type, void *v)
{
PR_ASSERT (server);
switch (prop)
{
case BSPROP_PARENT:
if (!BS_CHECK_TYPE (type, BSTYPE_OBJECT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
v = server->parent_network;
break;
case BSPROP_INPUT_TIMEOUT:
if (!BS_CHECK_TYPE (type, BSTYPE_UINT))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(bsuint *)v = server->input_timeout;
break;
case BSPROP_LINE_BUFFER:
if (!BS_CHECK_TYPE (type, BSTYPE_BOOLEAN))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
*(PRBool *)v = server->linebuffer_flag;
break;
case BSPROP_HOSTNAME:
if (!BS_CHECK_TYPE (type, BSTYPE_STRING))
{
BS_ReportError (BSERR_PROPERTY_MISMATCH);
return PR_FALSE;
}
v = server->hostname;
break;
default:
break;
}
return PR_FALSE;
}
PRBool
bs_server_get_uint_property (BSServerClass *server, BSServerProperty prop,
bsuint *v)
{
return bs_server_get_property (server, prop, BSTYPE_UINT, v);
}
PRBool
bs_server_get_string_property (BSServerClass *server, BSServerProperty prop,
bschar **v)
{
return bs_server_get_property (server, prop, BSTYPE_STRING, v);
}
PRBool
bs_server_get_bool_property (BSServerClass *server, BSServerProperty prop,
PRBool *v)
{
return bs_server_get_property (server, prop, BSTYPE_BOOLEAN, v);
}
PRBool
bs_server_get_object_property (BSServerClass *server, BSServerProperty prop,
BSServerClass **v)
{
return bs_server_get_property (server, prop, BSTYPE_OBJECT, v);
}
PR_END_EXTERN_C

View File

@ -1,98 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsserver_h___
#define bsserver_h___
#include "prtypes.h"
#include "bsnetwork.h"
PR_BEGIN_EXTERN_C
/* constructor */
extern BSServerClass *
bs_server_new (BSNetworkClass *parent, const char *hostname);
/* deallocator */
extern void
bs_server_free (BSServerClass *server);
/* connect to the server. Basically, a connection factory */
extern BSConnectionClass *
bs_server_connect (BSServerClass *server, bsint port, const bschar *bind_addr,
PRBool tcp);
/* poll all connections */
PRBool
bs_server_poll_connections (BSServerClass *server, BSQueueClass *event_queue);
/* route an event, friends only */
BSEventClass *
bs_server_route (BSServerClass *server, BSEventClass *event);
/* changes an event handler */
extern PRBool
bs_server_set_handler (BSServerClass *server,
BSServerEvent event_type,
BSServerEventCallback *handler);
/* property access routines */
extern PRBool
bs_server_set_uint_property (BSServerClass *server, BSServerProperty prop,
bsuint *v);
extern PRBool
bs_server_set_string_property (BSServerClass *server, BSServerProperty prop,
bschar *v);
extern PRBool
bs_server_set_bool_property (BSServerClass *server, BSServerProperty prop,
PRBool *v);
extern PRBool
bs_server_set_object_property (BSServerClass *server, BSServerProperty prop,
void *v);
extern PRBool
bs_server_get_uint_property (BSServerClass *server, BSServerProperty prop,
bsuint *v);
extern PRBool
bs_server_get_string_property (BSServerClass *server, BSServerProperty prop,
bschar **v);
extern PRBool
bs_server_get_bool_property (BSServerClass *server, BSServerProperty prop,
PRBool *v);
extern PRBool
bs_server_get_object_property (BSServerClass *server, BSServerProperty prop,
BSServerClass **v);
PR_END_EXTERN_C
#endif /* bsserver_h___ */

View File

@ -1,159 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
* Simon Fraser, smfr@netscape.com, Mac warning fixes
*/
#include <string.h>
#include "prtypes.h"
#include "prmem.h"
#include "prprf.h"
#include "prnetdb.h"
#include "bspubtd.h"
#include "bserror.h"
PR_BEGIN_EXTERN_C
PRBool
bs_util_is_ip (char *str)
{
bsuint length;
bsuint decimals = 0;
int i;
length = strlen (str);
for (i = 0; i < length; i++)
{
switch (str[i])
{
case '.':
decimals++;
if (decimals > 3)
return PR_FALSE;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
default:
/* bad character, bail */
return PR_FALSE;
}
}
return PR_TRUE;
}
PRStatus
bs_util_resolve_host (const char *hostname, PRNetAddr *na)
{
PRStatus rv;
bschar buf[PR_NETDB_BUF_SIZE];
PRHostEnt he;
rv = PR_GetHostByName (hostname, buf, PR_NETDB_BUF_SIZE, &he);
if (PR_FAILURE == rv)
return rv;
return (PRStatus)PR_EnumerateHostEnt (0, &he, 0, na);
}
bschar *
bs_util_linebuffer (bschar *newline, bschar **buffer, PRBool flush)
{
if (!newline)
return NULL;
*buffer = PR_sprintf_append(*buffer, "%s", newline);
if (!buffer)
{
BS_ReportError (BSERR_OUT_OF_MEMORY);
return NULL;
}
if ((newline[strlen(newline) - 1] == '\n') || flush)
return *buffer;
else
return NULL;
}
/*
* turns a buffer full of |delim| delimeted lines into
* an array of \00 delimeted strings. Make sure to
* free the return value AND the longbuf when you're done with them.
*/
char **
bs_util_delimbuffer_to_array (char *longbuf, int *lines, char delim)
{
int buflen;
int i, line;
char **lineary;
*lines = 0;
buflen = strlen (longbuf);
for (i=0; i<buflen; i++)
if (longbuf[i] == delim)
(*lines)++;
if (longbuf[buflen - 1] != delim)
(*lines)++;
lineary = (char **) PR_Malloc ((*lines) * sizeof (char *));
if (!lineary)
return NULL;
i=0;
line=0;
while (i<buflen)
{
lineary[line++] = &longbuf[i];
while ((longbuf[i] != delim) && (i < buflen)) i++;
if (i < buflen) longbuf[i] = '\00';
i++;
}
return lineary;
}
PR_END_EXTERN_C

View File

@ -1,46 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Basic Socket Library
*
* The Initial Developer of the Original Code is New Dimensions Consulting,
* Inc. Portions created by New Dimensions Consulting, Inc. are
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
* Rights Reserved.
*
* Contributor(s):
*
*
* Contributor(s):
* Robert Ginda, rginda@ndcico.com, original author
*/
#ifndef bsutil_h___
#define bsutil_h___
PR_BEGIN_EXTERN_C
extern PRBool
bs_util_is_ip (char *str);
extern PRStatus
bs_util_resolve_host (const char *hostname, PRNetAddr *na);
extern bschar *
bs_util_linebuffer (bschar *newline, bschar **buffer, PRBool flush);
extern char **
bs_util_delimbuffer_to_array (char *longbuf, int *lines, char delim);
PR_END_EXTERN_C
#endif /* bsutil_h___ */

View File

@ -1,78 +0,0 @@
/*
* Copyright (C) 1999 Robert Ginda
* All Rights Reserved
*/
#include <stdio.h>
#include "prtypes.h"
#include "prinit.h"
#include "bsapi.h"
#include "bsnetwork.h"
#include "bsserver.h"
#include "bsconnection.h"
BSEventClass *
sample_onRawData (BSConnectionClass *connection, BSEventClass *event)
{
fprintf (stdout, "rawdata event '%s'\n", (bschar *)event->data);
return NULL;
}
int
main (int argc, char **argv)
{
BSNetworkClass *network;
BSServerClass *server;
BSConnectionClass *connection1, *connection2;
bsuint event_count;
PRBool lb;
PRIntervalTime to;
network = bs_network_new ("EchoNet");
server = bs_network_add_server (network, "127.0.0.1");
connection1 = bs_server_connect (server, 7, NULL, PR_TRUE);
bs_connection_set_handler (connection1, BSEVENT_CONNECTION_RAWDATA,
sample_onRawData);
connection2 = bs_server_connect (server, 7, NULL, PR_TRUE);
bs_connection_set_handler (connection2, BSEVENT_CONNECTION_RAWDATA,
sample_onRawData);
bs_connection_get_bool_property (connection1, BSPROP_LINE_BUFFER, &lb);
printf ("Connection 1 linebuffer flag: %i\n", lb);
bs_connection_set_bool_property (connection1, BSPROP_LINE_BUFFER,
PR_FALSE);
bs_connection_get_bool_property (connection1, BSPROP_LINE_BUFFER, &lb);
printf ("Set connection 1 linebuffer flag: %i\n", lb);
bs_connection_send_string (connection1, "hello\nconnection 1\n");
bs_connection_send_string (connection2, "hello connection 2\n");
to = PR_MillisecondsToInterval (1000);
do
{
PR_Sleep (to);
bs_network_poll_servers (network);
bs_network_step_events (network, &event_count);
} while (event_count > 0);
bs_network_free (network);
return PR_Cleanup();
}

View File

@ -1,63 +0,0 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is windows makefile for Basic Socket Library.
#
# The Initial Developer of the Original Code is Netscape Communications,
# Inc. Portions created by Netscape Communications are
# Copyright (C) Netscape Communications, Inc. All
# Rights Reserved.
#
# Contributor(s):
# leaf (daniel nunes) <leaf@mozilla.org>
#
DEPTH=..\..\..
MAKE_OBJ_TYPE = DLL
MODULE=bs
DLL=.\$(OBJDIR)\$(MODULE).dll
LLIBS = \
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(NULL)
XPIDLSRCS = \
.\bsIConnection.idl \
$(NULL)
OBJS = \
.\$(OBJDIR)\bsutil.obj \
.\$(OBJDIR)\bserror.obj \
.\$(OBJDIR)\bsevent.obj \
.\$(OBJDIR)\bsqueue.obj \
.\$(OBJDIR)\bsnetwork.obj \
.\$(OBJDIR)\bsserver.obj \
.\$(OBJDIR)\bsconnection.obj \
.\$(OBJDIR)\bsXPCConnection.obj \
.\$(OBJDIR)\bsXPCConnectionFactory.obj \
$(NULL)
LIBRARY_NAME = bs
IS_COMPONENT = 1
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib
clobber::
$(RM) $(DIST)\bin\components\$(MODULE).dll
$(RM) $(DIST)\lib\$(MODULE).lib