void* AXIS2_THREAD_FUNC
axis2_amqp_request_processor_thread_function(
    axutil_thread_t* thread,
    void* request_data)
{
    axis2_status_t status = AXIS2_FAILURE;
    axutil_env_t* env = NULL;
    axutil_env_t* thread_env = NULL;
    axis2_amqp_request_processor_resource_pack_t* request_resource_pack = NULL;

#ifndef WIN32
#ifdef AXIS2_SVR_MULTI_THREADED
    signal(SIGPIPE, SIG_IGN);
#endif
#endif

    request_resource_pack = (axis2_amqp_request_processor_resource_pack_t*)request_data;

    env = request_resource_pack->env;
    thread_env = axutil_init_thread_env(env);

    /* Process Request */
    status = axis2_amqp_process_request(thread_env, request_resource_pack);

    if(status == AXIS2_SUCCESS)
    {
        AXIS2_LOG_INFO(thread_env->log, "Request Processed Successfully");
    }
    else
    {
        AXIS2_LOG_WARNING(thread_env->log, AXIS2_LOG_SI, "Error while Processing Request");
    }

    AXIS2_FREE(thread_env->allocator, request_resource_pack->request_content);
    AXIS2_FREE(thread_env->allocator, request_resource_pack->reply_to);
    AXIS2_FREE(thread_env->allocator, request_resource_pack->content_type);
    AXIS2_FREE(thread_env->allocator, request_resource_pack->soap_action);

    AXIS2_FREE(thread_env->allocator, request_resource_pack);

    if(thread_env)
    {
        thread_env = NULL;
    }

#ifdef AXIS2_SVR_MULTI_THREADED
    axutil_thread_pool_exit_thread(env->thread_pool, thread);
#endif

    return NULL;
}
Exemple #2
0
axis2_status_t AXIS2_CALL
axis2_udp_receiver_start(
    axis2_transport_receiver_t *tr_receiver,
    const axutil_env_t * env)
{
	axis2_status_t status;
	axis2_udp_receiver_impl_t *receiver = NULL;

	receiver = AXIS2_INTF_TO_IMPL(tr_receiver);

	AXIS2_LOG_INFO(env->log, "Started the UDP server");
	if (receiver->socket == AXIS2_INVALID_SOCKET)
	{
		/* socket not set, we should create one */
		if (receiver->is_multicast && receiver->multicast_group)
		{
			/* Setup a socket to receive multicast packets */
			receiver->socket = axutil_network_hadler_create_multicast_svr_socket(
				env, receiver->port, receiver->multicast_group);		
		}
		else
		{
			axis2_ctx_t *ctx = NULL;
			/* Setup a socket to receive unicast packets */
			receiver->socket = axutil_network_handler_create_dgram_svr_socket(
				env, receiver->port);
			receiver->owns_socket = AXIS2_TRUE; 
			/* bind the socket to a unique address */
			/*axutil_network_handler_bind_socket(env, receiver->socket, 0);*/
			ctx = axis2_conf_ctx_get_base(receiver->conf_ctx, env);
			axis2_udp_transport_add_backchannel_info(env, ctx, receiver->socket);
		}
		receiver->owns_socket = AXIS2_TRUE;
	}
	if (receiver->socket == AXIS2_INVALID_SOCKET)
	{
		AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Socket creation faild on socket");
		return AXIS2_FAILURE;
	}

	/* We are using a seperate socket to send the request */
	receiver->send_socket = axutil_network_handler_open_dgram_socket(env);
	if (receiver->send_socket == AXIS2_INVALID_SOCKET)
	{
		AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Socket creation faild on socket");
		return AXIS2_FAILURE;
	}
	receiver->stop =  AXIS2_FALSE;
	axutil_thread_mutex_unlock(receiver->mutex);
	while (!receiver->stop)
	{
		axis2_udp_recv_thd_args_t *args = NULL;
		axutil_thread_t *worker_thread = NULL;
		axis2_char_t *addr = NULL;
		int port = receiver->port;		
		int buf_len = AXIS2_UDP_PACKET_MAX_SIZE;
		axis2_char_t *in_buff = NULL;

		in_buff = AXIS2_MALLOC(env->allocator, sizeof(char) * receiver->max_packet_size);
		/* This is a blocking call. This will block until data is available in the socket */
		status = axutil_network_handler_read_dgram(env, receiver->socket, in_buff, &buf_len, &addr, &port);   
		if (status == AXIS2_FAILURE)
		{
			AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error in reading data from the datagram.");
			return AXIS2_FAILURE;
		}	

		args = (axis2_udp_recv_thd_args_t *)AXIS2_MALLOC(env->allocator, sizeof(axis2_udp_recv_thd_args_t));		
		if (!args)
		{
			AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
			return AXIS2_FAILURE;
		}
		/* Set the data required by the thread */
		args->env = axutil_init_thread_env(env);
		args->socket = receiver->socket;
		args->send_socket = receiver->send_socket;
		args->conf_ctx = receiver->conf_ctx;
		args->req_addr = addr;
		args->req_port = port;
		args->request.buff = in_buff;
		args->request.buf_size = buf_len;
		args->request.op = NULL;
		args->request.svc = NULL;
		args->is_multicast = receiver->is_multicast;
#ifdef AXIS2_SVR_MULTI_THREADED
		worker_thread = axutil_thread_pool_get_thread(env->thread_pool,
													axis2_udp_receiver_thread_worker_func,
													(void *) args);
		if (!worker_thread)
		{
			AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Thread creation failed"
							"server thread loop");
			continue;
		}
		axutil_thread_pool_thread_detach(env->thread_pool, worker_thread);
#else
		axis2_udp_receiver_thread_worker_func(NULL, (void *)args);
#endif
	}
	return AXIS2_SUCCESS;
}