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