loudmouth/lm-socket.c
changeset 552 137471c948ae
parent 346 ca353cc81e9a
child 575 daad23d59b56
equal deleted inserted replaced
514:31d914756fde 552:137471c948ae
   202 		case G_IO_STATUS_EOF:
   202 		case G_IO_STATUS_EOF:
   203 			*reason = LM_DISCONNECT_REASON_HUP;
   203 			*reason = LM_DISCONNECT_REASON_HUP;
   204 			break;
   204 			break;
   205 		case G_IO_STATUS_AGAIN:
   205 		case G_IO_STATUS_AGAIN:
   206 			/* No data readable but we didn't hangup */
   206 			/* No data readable but we didn't hangup */
       
   207 			/* No need to do anything since we will get a new in_event when data is 
       
   208 			 * available or writable. */
   207 			return FALSE;
   209 			return FALSE;
   208 			break;
   210 			break;
   209 		case G_IO_STATUS_ERROR:
   211 		case G_IO_STATUS_ERROR:
   210 			*reason = LM_DISCONNECT_REASON_ERROR;
   212 			*reason = LM_DISCONNECT_REASON_ERROR;
   211 			break;
   213 			break;
   223 
   225 
   224 	/* There is more data to be read */
   226 	/* There is more data to be read */
   225 	return TRUE;
   227 	return TRUE;
   226 }
   228 }
   227 
   229 
       
   230 /* 
       
   231  * When a non-blocking socket is used we will simply try to read again but when using a blocking socket
       
   232  * it means that the read operation will block in case there is no data available. 
       
   233  * This function checks if the socket is in blocking mode and checks the IO Condition to see whether there
       
   234  * is more data to be read before trying to read again
       
   235  */
       
   236 static gboolean
       
   237 socket_attempt_another_read (LmSocket *socket, GIOCondition condition)
       
   238 {
       
   239 	if (socket->blocking) {
       
   240 		return (condition & G_IO_IN); 
       
   241 	}
       
   242 
       
   243 	return TRUE;
       
   244 }
       
   245 
   228 static gboolean
   246 static gboolean
   229 socket_in_event (GIOChannel   *source,
   247 socket_in_event (GIOChannel   *source,
   230 		     GIOCondition  condition,
   248 		     GIOCondition  condition,
   231 		     LmSocket     *socket)
   249 		     LmSocket     *socket)
   232 {
   250 {
   238 
   256 
   239 	if (!socket->io_channel) {
   257 	if (!socket->io_channel) {
   240 		return FALSE;
   258 		return FALSE;
   241 	}
   259 	}
   242 
   260 
   243 	while ((condition & G_IO_IN) && socket_read_incoming (socket, buf, IN_BUFFER_SIZE, 
   261 	while (socket_attempt_another_read (socket, condition) && 
       
   262 	       socket_read_incoming (socket, buf, IN_BUFFER_SIZE, 
   244 				     &bytes_read, &hangup, &reason)) {
   263 				     &bytes_read, &hangup, &reason)) {
   245 		
   264 		
   246 		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV [%d]:\n", 
   265 		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, "\nRECV [%d]:\n", 
   247 		       (int)bytes_read);
   266 		       (int)bytes_read);
   248 		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET, 
   267 		g_log (LM_LOG_DOMAIN, LM_LOG_LEVEL_NET,