예제 #1
0
void tcpConnectionWriterRunThread(TcpConnection tcpConnection){
    TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
    ArrayList tempList;
	  while(internal->active==TRUE){
                 environmentThreadLock(internal->thread);    
                 tempList=internal->commands;
                 internal->commands=arrayListCreate();
                 environmentThreadUnlock(internal->thread);
                 int i;
                 int length=arrayListSize(tempList);
                 Command command;
                 for(i=0; i < length;i++){
                       command=arrayListGetValueAt(tempList,i);
                       int result=tcpConnectionSend(tcpConnection,command);
                       if(result<0){
                              internal->active=FALSE;
                              distributionManagerHandleTcpConnectionListenerFailure(internal->distributionManager,internal,internal->coreManagerId);  
                              //TODO Free the commands
                              return;
                       }
                       commandFree(command);
                 }
                 arrayListFree(tempList);
                 // Lock to synchronize
                 environmentThreadLock(internal->thread);
                 if(arrayListSize(internal->commands)==0){
                    environmentThreadWait(internal->thread);
                 }
                 environmentThreadUnlock(internal->thread);
        }
    internal->readyForCleanup+=WRITER_READY_FOR_CLEANUP;
}
예제 #2
0
void tcpConnectionClose(TcpConnection tcpConnection){
	TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
	close(internal->sockfd);
	internal->active=FALSE;
        environmentThreadLock(internal->thread);
        environmentThreadNotify(internal->thread);
        environmentThreadUnlock(internal->thread);
}
예제 #3
0
void tcpConnectionPushCommand(TcpConnection tcpConnection,Command command){
        TcpConnectionInternal* internal=(TcpConnectionInternal*)tcpConnection;
        if(internal->active==TRUE){
            environmentThreadLock(internal->thread);
            arrayListAddLast(internal->commands,command);
            environmentThreadNotify(internal->thread);
            environmentThreadUnlock(internal->thread);
        }
}