📄 htnet.c
字号:
if (net) { net->host->channel = NULL; net->readStream = NULL; net->bytesRead = 0; net->headerBytesRead = 0; net->bytesWritten = 0; net->headerBytesWritten = 0; return YES; } return NO;}/* HTNet_delete** ------------** Deletes the HTNet object from the list of active requests and calls** any registered call back functions IF not the status is HT_IGNORE.** This is used if we have internal requests that the app doesn't know** about. We also see if we have pending requests that can be started** up now when we have a socket free.** The callback functions are called in the reverse order of which they** were registered (last one first)** Return YES if OK, else NO*/PUBLIC BOOL HTNet_delete (HTNet * net, int status){ HTTRACE(CORE_TRACE, "Net Object.. Delete %p and call AFTER filters\n" _ net); if (net) { HTRequest * request = net->request; /* ** If we have a premature close then recover the request. Otherwise ** break the link to the Host object and continue deleting the net ** object */ if (net->host) { HTHost_unregister (net->host, net, HTEvent_READ); HTHost_unregister (net->host, net, HTEvent_WRITE); if (status == HT_RECOVER_PIPE) { HTNet_clear(net); HTTRACE(CORE_TRACE, "Net Object.. Restarting request %p (retry=%d) with net object %p\n" _ request _ HTRequest_retrys(request) _ net); return YES; } HTHost_deleteNet(net->host, net, status); if (HTHost_doRecover(net->host)) HTHost_recoverPipe(net->host); } /* Remove object from the table of Net Objects */ unregister_net(net); free_net(net); /* Call AFTER filters */ HTNet_executeAfterAll(request, status); /* ** Truely delete the HTNet object. Thanks to Mikhail Grouchinski ** we now do this after having called the after filters so that ** these filters can use the information in the Net object */ return YES; } return NO;}PUBLIC BOOL HTNet_deleteDup (HTNet * dup){ return dup ? (unregister_net(dup) && free_net(dup)) : NO;}/* HTNet_deleteAll** ---------------** Deletes all HTNet object that might either be active or pending** We DO NOT call the AFTER filters - A crude way of saying goodbye!*/PUBLIC BOOL HTNet_deleteAll (void){ HTTRACE(CORE_TRACE, "Net Object.. Remove all Net objects, NO filters\n"); if (NetTable) { HTList * cur = NULL; HTNet * pres = NULL; int cnt; for (cnt=0; cnt<HT_XL_HASH_SIZE; cnt++) { if ((cur = NetTable[cnt])) { while ((pres = (HTNet *) HTList_nextObject(cur)) != NULL) { check_pending(pres); free_net(pres); } } HTList_delete(NetTable[cnt]); } HT_FREE(NetTable); HTNetCount = 0; return YES; } return NO;}/*** When pipelining, it is not possible to kill a single request ** as we then loose track of where we are in the pipe. It is ** therefore necessary to kill the whole pipeline.*/PUBLIC BOOL HTNet_killPipe (HTNet * net){ return (net && net->host) ? HTHost_killPipe(net->host) : NO;}/* HTNet_kill** ----------** Kill the request by calling the call back function with a request for ** closing the connection. Does not remove the object. This is done by** HTNet_delete() function which is called by the load routine.** Returns OK if success, NO on error*/PUBLIC BOOL HTNet_kill (HTNet * net){ if (net) { HTAlertCallback * cbf = HTAlert_find(HT_PROG_INTERRUPT); if (cbf) (*cbf)(net->request, HT_PROG_INTERRUPT, HT_MSG_NULL, NULL, NULL, NULL); HTTRACE(CORE_TRACE, "Net Object.. Killing %p\n" _ net); if (net->event.cbf) { (*(net->event.cbf))(HTNet_socket(net), net->event.param, HTEvent_CLOSE); return YES; } return unregister_net(net) && free_net(net); } HTTRACE(CORE_TRACE, "Net Object.. No object to kill\n"); return NO;}/* HTNet_killAll** -------------** Kills all registered net objects by calling the call** back function with a request for closing the connection. We do not** remove the HTNet object as it is done by HTNet_delete().** Returns OK if success, NO on error*/PUBLIC BOOL HTNet_killAll (void){ HTTRACE(CORE_TRACE, "Net Object.. Kill ALL Net objects!!!\n"); if (NetTable) { HTList * cur = NULL; HTNet * pres = NULL; int cnt; for (cnt=0; cnt<HT_XL_HASH_SIZE; cnt++) { if ((cur = NetTable[cnt])) { while ((pres = (HTNet *) HTList_lastObject(cur)) != NULL) HTNet_kill(pres); } } return YES; } HTTRACE(CORE_TRACE, "Net Object.. No objects to kill\n"); return NO;}/* ------------------------------------------------------------------------- *//* Connection Specifics *//* ------------------------------------------------------------------------- *//* HTNet_priority** --------------** Get the current priority of the Net object*/PUBLIC HTPriority HTNet_priority (HTNet * net){ return (net ? net->event.priority : HT_PRIORITY_INV);}/* HTNet_setPriority** -----------------** Set the current priority of the Net object** This will change the priority next time the thread is blocked*/PUBLIC BOOL HTNet_setPriority (HTNet * net, HTPriority priority){ if (net) { net->event.priority = priority; return YES; } return NO;}/* HTNet_Persistent** ----------------** Check whether the net object handles persistent connections** If we have a DNS entry then check that as well.*/PUBLIC BOOL HTNet_persistent (HTNet * net){ return (net && HTHost_isPersistent(net->host));}/* HTNet_persistent** ----------------** Set the net object to handle persistent connections** If we also have a DNS entry then update that as well*/PUBLIC BOOL HTNet_setPersistent (HTNet * net, BOOL persistent, HTTransportMode mode){ if (net) { BOOL result = HTHost_setPersistent(net->host, persistent, mode); HTTRACE(CORE_TRACE, "Net Object.. Persistent connection set %s %s\n" _ persistent ? "ON" : "OFF" _ result ? "succeeded" : "failed"); return result; } return NO;}/*** Context pointer to be used in context call back function*/PUBLIC BOOL HTNet_setContext (HTNet * net, void * context){ if (net) { net->context = context; return YES; } return NO;}PUBLIC void * HTNet_context (HTNet * net){ return net ? net->context : NULL;}/*** Get and set the socket number*/PUBLIC BOOL HTNet_setSocket (HTNet * net, SOCKET sockfd){ if (net && net->host && net->host->channel) { HTChannel_setSocket(net->host->channel, sockfd); return YES; } return NO;}PUBLIC SOCKET HTNet_socket (HTNet * net){ return (net && net->host && net->host->channel ? HTChannel_socket(net->host->channel) : INVSOC);}/*** Get and set the HTRequest object*/PUBLIC BOOL HTNet_setRequest (HTNet * net, HTRequest * request){ if (net && request) { net->request = request; return YES; } return NO;}PUBLIC HTRequest * HTNet_request (HTNet * net){ return (net ? net->request : NULL);}/*** Get and set the HTChannel object*/PUBLIC BOOL HTNet_setChannel (HTNet * net, HTChannel * channel){ return (net && channel) ? HTHost_setChannel(net->host, channel) : NO;}PUBLIC HTChannel * HTNet_channel (HTNet * net){ return net ? HTHost_channel(net->host) : NULL;}/*** Get and set the HTHost object*/PUBLIC BOOL HTNet_setHost (HTNet * net, HTHost * host){ if (net && host) { net->host = host; return YES; } return NO;}PUBLIC HTHost * HTNet_host (HTNet * net){ return (net ? net->host : NULL);}/*** Get and set the HTdns object*/PUBLIC BOOL HTNet_setDns (HTNet * net, HTdns * dns){ if (net && dns) { net->host->dns = dns; return YES; } return NO;}PUBLIC HTdns * HTNet_dns (HTNet * net){ return (net ? net->host->dns : NULL);}PUBLIC BOOL HTNet_setProtocol (HTNet * net, HTProtocol * protocol){ if (net && protocol) { net->protocol = protocol; return YES; } return NO;}PUBLIC HTProtocol * HTNet_protocol (HTNet * net){ return (net ? net->protocol : NULL);}PUBLIC BOOL HTNet_setTransport (HTNet * net, HTTransport * tp){ if (net && tp) { net->transport = tp; return YES; } return NO;}PUBLIC HTTransport * HTNet_transport (HTNet * net){ return (net ? net->transport : NULL);}PUBLIC BOOL HTNet_preemptive (HTNet * net){ return (net ? net->preemptive : NO);}/*** Create the output stream and bind it to the channel** Please read the description in the HTIOStream module on the parameters*/PUBLIC HTOutputStream * HTNet_getOutput (HTNet * me, void * param, int mode){ if (me && me->host && me->host->channel && me->transport) { HTTransport * tp = me->transport; HTChannel * ch = me->host->channel; HTOutputStream * output = (*tp->output_new)(me->host, ch, param, mode); HTChannel_setOutput(ch, output); return output; } HTTRACE(CORE_TRACE, "Host Object.. Can't create output stream\n"); return NULL;}PUBLIC HTEvent * HTNet_event (HTNet * net){ return net ? &net->event : NULL;}PUBLIC BOOL HTNet_setEventParam (HTNet * net, void * eventParam){ if (net) return HTEvent_setParam(&net->event, eventParam); return NO;}PUBLIC void * HTNet_eventParam (HTNet * net){ return net ? net->event.param : NULL;}PUBLIC BOOL HTNet_setEventCallback(HTNet * net, HTEventCallback * cbf){ if (net) return HTEvent_setCallback(&net->event, cbf); return NO;}PUBLIC HTEventCallback * HTNet_eventCallback(HTNet * net){ return net->event.cbf;}PUBLIC BOOL HTNet_setEventPriority(HTNet * net, HTPriority priority){ if (net) return HTEvent_setPriority(&net->event, priority); return NO;}PUBLIC HTPriority HTNet_eventPriority(HTNet * net){ return net->event.priority;}PUBLIC HTStream * HTNet_readStream(HTNet * net){ if (!net) return NULL; return net->readStream;}PUBLIC BOOL HTNet_setReadStream (HTNet * net, HTStream * stream){ if (net) { net->readStream = stream; return YES; } return NO;}/*** Should we do raw byte count at the network or later?** Normally it is later but in cases like FTP we need it** in the raw form*/PUBLIC BOOL HTNet_setRawBytesCount (HTNet * net, BOOL mode){ if (net) { net->countRawBytes = mode; return YES; } return NO;}PUBLIC BOOL HTNet_rawBytesCount (HTNet * net){ return (net && net->countRawBytes);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -