Zero buffer for test before buffer read.
This commit is contained in:
		
							parent
							
								
									ec39c1df1a
								
							
						
					
					
						commit
						7e43656c5c
					
				
							
								
								
									
										53
									
								
								Socket.cpp
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								Socket.cpp
									
									
									
									
									
								
							| @ -15,7 +15,7 @@ namespace core { | ||||
|    Socket::~Socket() { | ||||
|       free(buffer); | ||||
|       if(descriptor == -1) | ||||
| 	     return; | ||||
| 	return; | ||||
|       onUnregister(); | ||||
|       ePoll.unregisterSocket(this); | ||||
|       coreutils::Log(coreutils::LOG_DEBUG_3) << "Socket destroyed for socket " << descriptor << "."; | ||||
| @ -24,8 +24,8 @@ namespace core { | ||||
|     | ||||
|    void Socket::setDescriptor(int descriptor) { | ||||
|       if((descriptor == -1) && (errno == 24)) { | ||||
| 	      shutdown("Too many files open"); | ||||
| 	      throw coreutils::Exception("Too many files open. Refusing connection."); | ||||
| 	 shutdown("Too many files open"); | ||||
| 	 throw coreutils::Exception("Too many files open. Refusing connection."); | ||||
|       } | ||||
|       lock.lock(); | ||||
|       coreutils::Log(coreutils::LOG_DEBUG_3) << "Descriptor set to " << descriptor << " for Socket."; | ||||
| @ -67,23 +67,23 @@ namespace core { | ||||
|       if(event.events & EPOLLRDHUP) { | ||||
|          readHangup = true; | ||||
|          shutdown("hangup received"); | ||||
|       	lock.unlock(); | ||||
| 	 lock.unlock(); | ||||
|          return false; | ||||
|       } | ||||
|        | ||||
|       if(event.events & EPOLLIN) { | ||||
|          coreutils::ZString zbuffer(buffer, length); | ||||
|      	   receiveData(zbuffer); | ||||
| 	 receiveData(zbuffer); | ||||
|       } | ||||
|        | ||||
|       if(event.events & EPOLLWRNORM) { | ||||
| 	      writeSocket(); | ||||
| 	 writeSocket(); | ||||
|       } | ||||
|        | ||||
|       if(event.events & EPOLLHUP) { | ||||
|          shutdown(); | ||||
| 	      lock.unlock(); | ||||
| 	      return false; | ||||
| 	 lock.unlock(); | ||||
| 	 return false; | ||||
|       } | ||||
|        | ||||
|       lock.unlock(); | ||||
| @ -110,40 +110,43 @@ namespace core { | ||||
|       int len; | ||||
|       int error = -1; | ||||
|        | ||||
|       for(int ix = 0; ix < buffer.getLength(); ++ix) | ||||
|         buffer[ix] = 0; | ||||
| 
 | ||||
|       if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) { | ||||
|          coreutils::ZString zbuffer(buffer.getData(), len); | ||||
|     	   onDataReceived(zbuffer); | ||||
| 	      onDataReceived(zbuffer); | ||||
|       } | ||||
|       else { | ||||
| 	  | ||||
|    	   error = errno; | ||||
| 	 error = errno; | ||||
| 	  | ||||
| 	      switch (error) { | ||||
| 	 switch (error) { | ||||
| 	     | ||||
| 	         // When a listening socket receives a connection
 | ||||
| 	         // request we get one of these.
 | ||||
|            	//
 | ||||
| 	       case ENOTCONN: | ||||
| 	    // When a listening socket receives a connection
 | ||||
| 	    // request we get one of these.
 | ||||
| 	    //
 | ||||
| 	  case ENOTCONN: | ||||
|             onDataReceived(blank); | ||||
|            break; | ||||
| 	    break; | ||||
| 	     | ||||
|    	    case ECONNRESET: | ||||
| 	  case ECONNRESET: | ||||
|             break; | ||||
| 	     | ||||
|    	    default: | ||||
| 	  default: | ||||
|             throw coreutils::Exception("Error in read of data from socket.", __FILE__, __LINE__, error); | ||||
|    	   } | ||||
| 	 } | ||||
|       } | ||||
|    } | ||||
|     | ||||
|    void Socket::writeSocket() { | ||||
|       if(fifo.size() > 0) { | ||||
|    	   outlock.lock(); | ||||
| 	 outlock.lock(); | ||||
|          ::write(descriptor, fifo.front().c_str(), fifo.front().length()); | ||||
|          fifo.pop(); | ||||
| 	      if(shutDown && !needsToWrite()) | ||||
| 	        delete this; | ||||
| 	      outlock.unlock(); | ||||
| 	 if(shutDown && !needsToWrite()) | ||||
| 	   delete this; | ||||
| 	 outlock.unlock(); | ||||
|       } | ||||
|    } | ||||
|     | ||||
| @ -167,8 +170,8 @@ namespace core { | ||||
|       coreutils::Log(coreutils::LOG_DEBUG_2) << "Shutdown requested on socket " << descriptor << " with reason " << text << "."; | ||||
|       shutDown = true; | ||||
|       reset = false; | ||||
| //      if(!needsToWrite())
 | ||||
|    	  delete this; | ||||
|       //      if(!needsToWrite())
 | ||||
|       delete this; | ||||
|        | ||||
|    } | ||||
|     | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Brad Arant
						Brad Arant