Пример #1
0
int main(int argc, char **argv)
{
	Octstr *os1;
	Octstr *os2;
	time_t start, diff;

    gwlib_init();

    os1 = octstr_create(argv[1]);
    os2 = octstr_create(argv[2]);

    counter = counter_create();
    start = time(NULL);
    for_each_file(os1, 1, count_file);
    diff = (time(NULL) - start);
    debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff);

#ifdef HAVE_NFTW
    counter_set(counter, 0);
    start = time(NULL);
    for_each_file2(os2, 1, count_file2);
    diff = (time(NULL) - start);
    debug("",0,"file count: %ld in %lds", (long) counter_value(counter), (long) diff);
#endif

    counter_destroy(counter);
    octstr_destroy(os1);
    octstr_destroy(os2);
    gwlib_shutdown();
	return 0;
}
Пример #2
0
void smpp_listener_event(evutil_socket_t fd, short what, void *arg)
{
    SMPPEsme *smpp_esme = arg;
    SMPP_PDU *pdu = NULL;
    int result;
    SMPPQueuedPDU *smpp_queued_pdu;
    
    if(what & EV_READ) {
        debug("smpp.listener.event", 0, "Got a read event for SMPP esme connection %ld %d", smpp_esme->id, smpp_esme->bind_type);
        while((result = smpp_listener_read_pdu(smpp_esme, &smpp_esme->pending_len, &pdu)) > 0) {
            counter_set(smpp_esme->errors, 0L);
            smpp_queued_pdu = smpp_queued_pdu_create();
            smpp_queued_pdu->pdu = pdu;
            smpp_queued_pdu->smpp_esme = smpp_esme;
            smpp_queues_add_inbound(smpp_queued_pdu);
        }
        
        if(result == 0) {
            /* Just no data, who cares*/
        } else {
            if(result == -1) {
                error(0, "Could not read PDU from %s status was %d", octstr_get_cstr(smpp_esme->system_id), result);
                /* This is a connection error we can close this ESME */
                /* Stop listening on this connection, its dead */
                smpp_esme_stop_listening(smpp_esme);
                
                if(!smpp_esme->authenticated) { /* If there is a pending disconnect operation it means an unbind/rejected bind requested to disconnect, let outbound queue handle */
                    /* This bind is not authenticated so will never be cleaned up, lets do it here  */
                    debug("smpp.listener.event", 0, "Cleaning up disconnected ESME %ld", smpp_esme->id);
                    smpp_listener_auth_failed(smpp_esme->smpp_server, smpp_esme->ip);
                    smpp_esme_cleanup(smpp_esme);
                } else {
                    debug("smpp.listener.event", 0, "Allowing background thread to clean up %ld", smpp_esme->id);
                }
            } else if(result == -2) {
                error(0, "Could not read PDU from %s status was %d", octstr_get_cstr(smpp_esme->system_id), result);
                counter_increase(smpp_esme->errors);
                
                if(counter_value(smpp_esme->errors) >= SMPP_ESME_MAX_CONSECUTIVE_ERRORS) {
                    error(0, "SMPP[%s] max consecutive PDU errors, disconnecting", octstr_get_cstr(smpp_esme->system_id));
                    smpp_esme_stop_listening(smpp_esme);
                    
                    if(!smpp_esme->authenticated) {
                        /* This bind is not authenticated so will never be cleaned up, lets do it here  */
                        smpp_listener_auth_failed(smpp_esme->smpp_server, smpp_esme->ip);
                        smpp_esme_cleanup(smpp_esme);
                    } else {
                        debug("smpp.listener.event", 0, "Allowing background thread to clean up mangled %ld", smpp_esme->id);
                    }
                    
                }
            }
        }
    } else {
        debug("smpp.listener.event", 0, "Got a other event for SMPP esme connection %ld", smpp_esme->id);
    }
}
void child(void)
{
	int i;
	int counter;

	printf(1, "Process started...\n");
	sleep(10);

	for (i=0; i<TARGET_COUNT_PER_CHILD; i++) {
		sem_wait(SEMAPHORE_NUM, 1);
		
		counter = counter_get("counter");
		counter++;
		counter_set("counter", counter);

		sem_signal(SEMAPHORE_NUM, 1);
	}

	exit();
}
Пример #4
0
int smscconn_send(SMSCConn *conn, Msg *msg)
{
    int ret = -1;
    List *parts = NULL;
    
    gw_assert(conn != NULL);
    mutex_lock(conn->flow_mutex);
    if (conn->status == SMSCCONN_DEAD || conn->why_killed != SMSCCONN_ALIVE) {
        mutex_unlock(conn->flow_mutex);
        return -1;
    }

    /* if this a retry of splitted message, don't unify prefix and don't try to split */
    if (msg->sms.split_parts == NULL) {    
        /* normalize the destination number for this smsc */
        char *uf = conn->unified_prefix ? octstr_get_cstr(conn->unified_prefix) : NULL;
        normalize_number(uf, &(msg->sms.receiver));

        /* split msg */
        parts = sms_split(msg, NULL, NULL, NULL, NULL, 1, 
            counter_increase(split_msg_counter) & 0xff, 0xff, conn->max_sms_octets);
        if (gwlist_len(parts) == 1) {
            /* don't create split_parts of sms fit into one */
            gwlist_destroy(parts, msg_destroy_item);
            parts = NULL;
        }
    }
    
    if (parts == NULL)
        ret = conn->send_msg(conn, msg);
    else {
        long i, parts_len = gwlist_len(parts);
        struct split_parts *split = gw_malloc(sizeof(*split));
         /* must duplicate, because smsc2_route will destroy this msg */
        split->orig = msg_duplicate(msg);
        split->parts_left = counter_create();
        split->status = SMSCCONN_SUCCESS;
        counter_set(split->parts_left, parts_len);
        split->smsc_conn = conn;
        debug("bb.sms.splits", 0, "new split_parts created %p", split);
        for (i = 0; i < parts_len; i++) {
            msg = gwlist_get(parts, i);
            msg->sms.split_parts = split;
            ret = conn->send_msg(conn, msg);
            if (ret < 0) {
                if (i == 0) {
                    counter_destroy(split->parts_left);
                    gwlist_destroy(parts, msg_destroy_item);
                    gw_free(split);
                    mutex_unlock(conn->flow_mutex);
                    return ret;
                }
                /*
                 * Some parts were sent. So handle this within
                 * bb_smscconn_XXX().
                 */
                split->status = SMSCCONN_FAILED_REJECTED;
                counter_increase_with(split->parts_left, -(parts_len - i));
                warning(0, "Could not send all parts of a split message");
                break;
            }
        }
        gwlist_destroy(parts, msg_destroy_item);
    }
    mutex_unlock(conn->flow_mutex);
    return ret;
}
Пример #5
0
/*
 * Flush all DLR messages out of the spool, removing all.
 */
static void dlr_spool_flush(void)
{
    for_each_file(spool_dir, 1, unlink_file);
    counter_set(counter, 0);
}