Exemplo n.º 1
0
int mosquitto_loop_read(struct mosquitto *mosq, int max_packets)
{
	int rc;
	int i;
	if(max_packets < 1) return MOSQ_ERR_INVAL;

	pthread_mutex_lock(&mosq->out_message_mutex);
	max_packets = mosq->out_queue_len;
	pthread_mutex_unlock(&mosq->out_message_mutex);

	pthread_mutex_lock(&mosq->in_message_mutex);
	max_packets += mosq->in_queue_len;
	pthread_mutex_unlock(&mosq->in_message_mutex);

	if(max_packets < 1) max_packets = 1;
	/* Queue len here tells us how many messages are awaiting processing and
	 * have QoS > 0. We should try to deal with that many in this loop in order
	 * to keep up. */
	for(i=0; i<max_packets; i++){
#ifdef WITH_SOCKS
		if(mosq->socks5_host){
			rc = mosquitto__socks5_read(mosq);
		}else
#endif
		{
			rc = _mosquitto_packet_read(mosq);
		}
		if(rc || errno == EAGAIN || errno == COMPAT_EWOULDBLOCK){
			return _mosquitto_loop_rc_handle(mosq, rc);
		}
	}
	return rc;
}
Exemplo n.º 2
0
int mosquitto_loop_write(struct mosquitto *mosq, int max_packets)
{
	int rc;
	int i;
	if(max_packets < 1) return MOSQ_ERR_INVAL;

	pthread_mutex_lock(&mosq->out_message_mutex);
	max_packets = mosq->out_queue_len;
	pthread_mutex_unlock(&mosq->out_message_mutex);

	pthread_mutex_lock(&mosq->in_message_mutex);
	max_packets += mosq->in_queue_len;
	pthread_mutex_unlock(&mosq->in_message_mutex);

	if(max_packets < 1) max_packets = 1;
	/* Queue len here tells us how many messages are awaiting processing and
	 * have QoS > 0. We should try to deal with that many in this loop in order
	 * to keep up. */
					printf("==================================\n");
					printf("----------------------------------\n");
					printf("#Queue message : %d\n", max_packets);
					printf("----------------------------------\n");
					printf("==================================\n");
	for(i=0; i<max_packets; i++){
		rc = _mosquitto_packet_write(mosq);
		if(rc || errno == EAGAIN || errno == COMPAT_EWOULDBLOCK){
			return _mosquitto_loop_rc_handle(mosq, rc);
		}
	}
	return rc;
}
Exemplo n.º 3
0
int mosquitto_loop_write(struct mosquitto *mosq, int max_packets)
{
    int rc;
    int i;
    if(max_packets < 1) return MOSQ_ERR_INVAL;

    max_packets = mosq->queue_len;
    if(max_packets < 1) max_packets = 1;
    /* Queue len here tells us how many messages are awaiting processing and
     * have QoS > 0. We should try to deal with that many in this loop in order
     * to keep up. */
    for(i=0; i<max_packets; i++) {
        rc = _mosquitto_packet_write(mosq);
        if(rc || errno == EAGAIN || errno == COMPAT_EWOULDBLOCK) {
            return _mosquitto_loop_rc_handle(mosq, rc);
        }
    }
    return rc;
}