mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-31 02:52:30 +01:00
- replaced WMBag with WMArray in connection.c and host.c
- added WMGetConnectionUnsentData() (WMGetConnectionQueuedData() is an alias too)
This commit is contained in:
@@ -699,23 +699,23 @@ Bool WMIsHostEqualToHost(WMHost* hPtr, WMHost* anotherHost);
|
||||
/*
|
||||
* Host names.
|
||||
* WMGetHostName() will return first name (official) if a host has several.
|
||||
* WMGetHostNames() will return a R/O WMBag with all the names of the host.
|
||||
* WMGetHostNames() will return a R/O WMArray with all the names of the host.
|
||||
*/
|
||||
char* WMGetHostName(WMHost* hPtr);
|
||||
|
||||
/* The returned bag is R/O. Do not modify it, and do not free it! */
|
||||
WMBag* WMGetHostNames(WMHost* hPtr);
|
||||
/* The returned array is R/O. Do not modify it, and do not free it! */
|
||||
WMArray* WMGetHostNames(WMHost* hPtr);
|
||||
|
||||
/*
|
||||
* Host addresses.
|
||||
* Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
|
||||
* WMGetHostAddress() will return an arbitrary address if a host has several.
|
||||
* WMGetHostAddresses() will return a R/O WMBag with all addresses of the host.
|
||||
* WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
|
||||
*/
|
||||
char* WMGetHostAddress(WMHost* hPtr);
|
||||
|
||||
/* The returned bag is R/O. Do not modify it, and do not free it! */
|
||||
WMBag* WMGetHostAddresses(WMHost* hPtr);
|
||||
/* The returned array is R/O. Do not modify it, and do not free it! */
|
||||
WMArray* WMGetHostAddresses(WMHost* hPtr);
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
@@ -772,6 +772,11 @@ WMConnectionState WMGetConnectionState(WMConnection *cPtr);
|
||||
|
||||
WMConnectionTimeoutState WMGetConnectionTimeoutState(WMConnection *cPtr);
|
||||
|
||||
WMArray* WMGetConnectionUnsentData(WMConnection *cPtr);
|
||||
|
||||
#define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
|
||||
|
||||
|
||||
/*
|
||||
* Passing timeout==0 in the SetTimeout functions below, will reset that
|
||||
* timeout to its default value.
|
||||
|
||||
@@ -106,7 +106,7 @@ typedef struct W_Connection {
|
||||
void *clientData; /* client data */
|
||||
unsigned int uflags; /* flags for the client */
|
||||
|
||||
WMBag *outputQueue;
|
||||
WMArray *outputQueue;
|
||||
unsigned bufPos;
|
||||
|
||||
TimeoutData sendTimeout;
|
||||
@@ -130,14 +130,8 @@ typedef struct W_Connection {
|
||||
static void
|
||||
clearOutputQueue(WMConnection *cPtr) /*FOLD00*/
|
||||
{
|
||||
int i;
|
||||
|
||||
cPtr->bufPos = 0;
|
||||
|
||||
for (i=0; i<WMGetBagItemCount(cPtr->outputQueue); i++)
|
||||
WMReleaseData(WMGetFromBag(cPtr->outputQueue, i));
|
||||
|
||||
WMEmptyBag(cPtr->outputQueue);
|
||||
WMEmptyArray(cPtr->outputQueue);
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +168,7 @@ sendTimeout(void *cdata) /*FOLD00*/
|
||||
WMDeleteInputHandler(cPtr->handler.write);
|
||||
cPtr->handler.write = NULL;
|
||||
}
|
||||
if (WMGetBagItemCount(cPtr->outputQueue)>0) {
|
||||
if (WMGetArrayItemCount(cPtr->outputQueue)>0) {
|
||||
clearOutputQueue(cPtr);
|
||||
cPtr->state = WCTimedOut;
|
||||
cPtr->timeoutState = WCTWhileSending;
|
||||
@@ -372,7 +366,8 @@ createConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/
|
||||
cPtr->sendTimeout.timeout = DefaultTimeout;
|
||||
cPtr->sendTimeout.handler = NULL;
|
||||
cPtr->closeOnRelease = closeOnRelease;
|
||||
cPtr->outputQueue = WMCreateBag(16);
|
||||
cPtr->outputQueue =
|
||||
WMCreateArrayWithDestructor(16, (WMFreeDataProc*)WMReleaseData);
|
||||
cPtr->state = WCNotConnected;
|
||||
cPtr->timeoutState = WCTNone;
|
||||
|
||||
@@ -641,8 +636,7 @@ WMDestroyConnection(WMConnection *cPtr) /*FOLD00*/
|
||||
}
|
||||
|
||||
removeAllHandlers(cPtr);
|
||||
clearOutputQueue(cPtr);
|
||||
WMFreeBag(cPtr->outputQueue);
|
||||
WMFreeArray(cPtr->outputQueue); /* will also free the items with the destructor */
|
||||
|
||||
if (cPtr->address) {
|
||||
wfree(cPtr->address);
|
||||
@@ -756,7 +750,7 @@ WMEnqueueConnectionData(WMConnection *cPtr, WMData *data) /*FOLD00*/
|
||||
if (cPtr->state!=WCConnected)
|
||||
return False;
|
||||
|
||||
WMPutInBag(cPtr->outputQueue, WMRetainData(data));
|
||||
WMAddToArray(cPtr->outputQueue, WMRetainData(data));
|
||||
return True;
|
||||
}
|
||||
|
||||
@@ -776,19 +770,19 @@ WMSendConnectionData(WMConnection *cPtr, WMData *data) /*FOLD00*/
|
||||
|
||||
/* If we have no data just flush the queue, else try to send data */
|
||||
if (data && WMGetDataLength(data)>0) {
|
||||
WMPutInBag(cPtr->outputQueue, WMRetainData(data));
|
||||
WMAddToArray(cPtr->outputQueue, WMRetainData(data));
|
||||
/* If there already was something in queue, and also a write input
|
||||
* handler is established, it means we were unable to send, so
|
||||
* return and let the write handler notify us when we can send.
|
||||
*/
|
||||
if (WMGetBagItemCount(cPtr->outputQueue)>1 && cPtr->handler.write)
|
||||
if (WMGetArrayItemCount(cPtr->outputQueue)>1 && cPtr->handler.write)
|
||||
return 0;
|
||||
}
|
||||
|
||||
totalTransfer = 0;
|
||||
|
||||
while (WMGetBagItemCount(cPtr->outputQueue) > 0) {
|
||||
data = WMGetFromBag(cPtr->outputQueue, 0);
|
||||
while (WMGetArrayItemCount(cPtr->outputQueue) > 0) {
|
||||
data = WMGetFromArray(cPtr->outputQueue, 0);
|
||||
dataBytes = (const unsigned char *)WMDataBytes(data);
|
||||
len = WMGetDataLength(data);
|
||||
pos = cPtr->bufPos; /* where we're left last time */
|
||||
@@ -815,7 +809,6 @@ WMSendConnectionData(WMConnection *cPtr, WMData *data) /*FOLD00*/
|
||||
default:
|
||||
WCErrorCode = errno;
|
||||
cPtr->state = WCDied;
|
||||
/*clearOutputQueue(cPtr);*/
|
||||
removeAllHandlers(cPtr);
|
||||
if (cPtr->delegate && cPtr->delegate->didDie)
|
||||
(*cPtr->delegate->didDie)(cPtr->delegate, cPtr);
|
||||
@@ -825,8 +818,7 @@ WMSendConnectionData(WMConnection *cPtr, WMData *data) /*FOLD00*/
|
||||
pos += bytes;
|
||||
totalTransfer += bytes;
|
||||
}
|
||||
WMReleaseData(data);
|
||||
WMDeleteFromBag(cPtr->outputQueue, 0);
|
||||
WMDeleteFromArray(cPtr->outputQueue, 0);
|
||||
cPtr->bufPos = 0;
|
||||
if (tPtr->handler) {
|
||||
WMDeleteTimerHandler(tPtr->handler);
|
||||
@@ -840,7 +832,7 @@ WMSendConnectionData(WMConnection *cPtr, WMData *data) /*FOLD00*/
|
||||
|
||||
return totalTransfer;
|
||||
}
|
||||
/*FOLD00*/
|
||||
|
||||
|
||||
/*
|
||||
* WMGetConnectionAvailableData(connection):
|
||||
@@ -914,7 +906,7 @@ WMSetConnectionDelegate(WMConnection *cPtr, ConnectionDelegate *delegate) /*FOLD
|
||||
cPtr->handler.exception = WMAddInputHandler(cPtr->sock, WIExceptMask,
|
||||
inputHandler, cPtr);
|
||||
}
|
||||
/*FOLD00*/
|
||||
|
||||
|
||||
#if 0
|
||||
Bool
|
||||
@@ -983,6 +975,13 @@ WMSetConnectionFlags(WMConnection *cPtr, unsigned int flags) /*FOLD00*/
|
||||
}
|
||||
|
||||
|
||||
WMArray*
|
||||
WMGetConnectionUnsentData(WMConnection *cPtr)
|
||||
{
|
||||
return cPtr->outputQueue;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WMSetConnectionDefaultTimeout(unsigned int timeout) /*FOLD00*/
|
||||
{
|
||||
|
||||
59
WINGs/host.c
59
WINGs/host.c
@@ -43,8 +43,8 @@
|
||||
typedef struct W_Host {
|
||||
char *name;
|
||||
|
||||
WMBag *names;
|
||||
WMBag *addresses;
|
||||
WMArray *names;
|
||||
WMArray *addresses;
|
||||
|
||||
int refCount;
|
||||
} W_Host;
|
||||
@@ -76,19 +76,19 @@ getHostWithHostEntry(struct hostent *host, char *name)
|
||||
hPtr = (WMHost*)wmalloc(sizeof(WMHost));
|
||||
memset(hPtr, 0, sizeof(WMHost));
|
||||
|
||||
hPtr->names = WMCreateBag(1);
|
||||
hPtr->addresses = WMCreateBag(1);
|
||||
hPtr->names = WMCreateArrayWithDestructor(1, wfree);
|
||||
hPtr->addresses = WMCreateArrayWithDestructor(1, wfree);
|
||||
|
||||
WMPutInBag(hPtr->names, wstrdup(host->h_name));
|
||||
WMAddToArray(hPtr->names, wstrdup(host->h_name));
|
||||
|
||||
for (i=0; host->h_aliases[i]!=NULL; i++) {
|
||||
WMPutInBag(hPtr->names, wstrdup(host->h_aliases[i]));
|
||||
WMAddToArray(hPtr->names, wstrdup(host->h_aliases[i]));
|
||||
}
|
||||
|
||||
for (i=0; host->h_addr_list[i]!=NULL; i++) {
|
||||
memcpy((void*)&in.s_addr, (const void*)host->h_addr_list[i],
|
||||
host->h_length);
|
||||
WMPutInBag(hPtr->addresses, wstrdup(inet_ntoa(in)));
|
||||
WMAddToArray(hPtr->addresses, wstrdup(inet_ntoa(in)));
|
||||
}
|
||||
|
||||
hPtr->refCount = 1;
|
||||
@@ -122,7 +122,7 @@ WMGetCurrentHost()
|
||||
|
||||
|
||||
WMHost*
|
||||
WMGetHostWithName(char* name)
|
||||
WMGetHostWithName(char *name)
|
||||
{
|
||||
struct hostent *host;
|
||||
WMHost *hPtr;
|
||||
@@ -151,7 +151,7 @@ WMGetHostWithName(char* name)
|
||||
|
||||
|
||||
WMHost*
|
||||
WMGetHostWithAddress(char* address)
|
||||
WMGetHostWithAddress(char *address)
|
||||
{
|
||||
struct hostent *host;
|
||||
struct in_addr in;
|
||||
@@ -206,13 +206,8 @@ WMReleaseHost(WMHost *hPtr)
|
||||
if (hPtr->refCount > 0)
|
||||
return;
|
||||
|
||||
for (i=0; i<WMGetBagItemCount(hPtr->names); i++)
|
||||
wfree(WMGetFromBag(hPtr->names, i));
|
||||
for (i=0; i<WMGetBagItemCount(hPtr->addresses); i++)
|
||||
wfree(WMGetFromBag(hPtr->addresses, i));
|
||||
|
||||
WMFreeBag(hPtr->names);
|
||||
WMFreeBag(hPtr->addresses);
|
||||
WMFreeArray(hPtr->names);
|
||||
WMFreeArray(hPtr->addresses);
|
||||
|
||||
if (hPtr->name) {
|
||||
WMHashRemove(hostCache, hPtr->name);
|
||||
@@ -241,7 +236,7 @@ void
|
||||
WMFlushHostCache()
|
||||
{
|
||||
if (hostCache && WMCountHashTable(hostCache)>0) {
|
||||
WMBag *hostBag = WMCreateBag(WMCountHashTable(hostCache));
|
||||
WMArray *hostArray = WMCreateArray(WMCountHashTable(hostCache));
|
||||
WMHashEnumerator enumer = WMEnumerateHashTable(hostCache);
|
||||
WMHost *hPtr;
|
||||
int i;
|
||||
@@ -249,11 +244,11 @@ WMFlushHostCache()
|
||||
while ((hPtr = WMNextHashEnumeratorItem(&enumer))) {
|
||||
/* we can't release the host here, because we can't change the
|
||||
* hash while using the enumerator functions. */
|
||||
WMPutInBag(hostBag, hPtr);
|
||||
WMAddToArray(hostArray, hPtr);
|
||||
}
|
||||
for (i=0; i<WMGetBagItemCount(hostBag); i++)
|
||||
WMReleaseHost(WMGetFromBag(hostBag, i));
|
||||
WMFreeBag(hostBag);
|
||||
for (i=0; i<WMGetArrayItemCount(hostArray); i++)
|
||||
WMReleaseHost(WMGetFromArray(hostArray, i));
|
||||
WMFreeArray(hostArray);
|
||||
WMResetHashTable(hostCache);
|
||||
}
|
||||
}
|
||||
@@ -270,10 +265,10 @@ WMIsHostEqualToHost(WMHost* hPtr, WMHost* aPtr)
|
||||
if (hPtr == aPtr)
|
||||
return True;
|
||||
|
||||
for (i=0; i<WMGetBagItemCount(aPtr->addresses); i++) {
|
||||
adr1 = WMGetFromBag(aPtr->addresses, i);
|
||||
for (j=0; j<WMGetBagItemCount(hPtr->addresses); j++) {
|
||||
adr2 = WMGetFromBag(hPtr->addresses, j);
|
||||
for (i=0; i<WMGetArrayItemCount(aPtr->addresses); i++) {
|
||||
adr1 = WMGetFromArray(aPtr->addresses, i);
|
||||
for (j=0; j<WMGetArrayItemCount(hPtr->addresses); j++) {
|
||||
adr2 = WMGetFromArray(hPtr->addresses, j);
|
||||
if (strcmp(adr1, adr2)==0)
|
||||
return True;
|
||||
}
|
||||
@@ -286,13 +281,13 @@ WMIsHostEqualToHost(WMHost* hPtr, WMHost* aPtr)
|
||||
char*
|
||||
WMGetHostName(WMHost *hPtr)
|
||||
{
|
||||
return (WMGetBagItemCount(hPtr->names) > 0 ?
|
||||
WMGetFromBag(hPtr->names, 0) : NULL);
|
||||
/*return WMGetFromBag(hPtr->names, 0);*/
|
||||
return (WMGetArrayItemCount(hPtr->names) > 0 ?
|
||||
WMGetFromArray(hPtr->names, 0) : NULL);
|
||||
/*return WMGetFromArray(hPtr->names, 0);*/
|
||||
}
|
||||
|
||||
|
||||
WMBag*
|
||||
WMArray*
|
||||
WMGetHostNames(WMHost *hPtr)
|
||||
{
|
||||
return hPtr->names;
|
||||
@@ -302,12 +297,12 @@ WMGetHostNames(WMHost *hPtr)
|
||||
char*
|
||||
WMGetHostAddress(WMHost *hPtr)
|
||||
{
|
||||
return (WMGetBagItemCount(hPtr->addresses) > 0 ?
|
||||
WMGetFromBag(hPtr->addresses, 0) : NULL);
|
||||
return (WMGetArrayItemCount(hPtr->addresses) > 0 ?
|
||||
WMGetFromArray(hPtr->addresses, 0) : NULL);
|
||||
}
|
||||
|
||||
|
||||
WMBag*
|
||||
WMArray*
|
||||
WMGetHostAddresses(WMHost *hPtr)
|
||||
{
|
||||
return hPtr->addresses;
|
||||
|
||||
Reference in New Issue
Block a user