int main (int argc, char ** argv) { VortexCtx * ctx; /* create a context */ ctx = vortex_ctx_new (); vortex_log_enable (ctx, axl_true); vortex_color_log_enable (ctx, axl_true); signal (SIGSEGV, __sigsegv_handler); signal (SIGABRT, __sigsegv_handler); /* init vortex library */ if (! vortex_init_ctx (ctx)) { printf ("Failed to start vortex library..\n"); return -1; } /* register a profile */ vortex_profiles_register (ctx, COYOTE_PROFILE, start_channel, NULL, NULL, NULL, frame_received, NULL); /* create a vortex server */ vortex_listener_new (ctx, "0.0.0.0", "44000", on_ready, ctx); /* wait for listeners (until vortex_exit is called) */ vortex_listener_wait (ctx); /* terminate library execution */ vortex_exit_ctx (ctx, axl_true); return 0; }
int main (int argc, char ** argv) { /* create the context */ ctx = vortex_ctx_new (); /* init vortex library */ if (! vortex_init_ctx (ctx)) { /* unable to init context */ vortex_ctx_free (ctx); return -1; } /* end if */ /* register a profile */ vortex_profiles_register (ctx, PLAIN_PROFILE, start_channel, NULL, close_channel, NULL, frame_received, NULL); vortex_greetings_set_features (ctx, "enable-tls"); vortex_greetings_set_localize (ctx, "es-ES"); /* create a vortex server */ vortex_listener_new (ctx, "0.0.0.0", "44000", NULL, NULL); /* wait for listeners (until vortex_exit is called) */ vortex_listener_wait (ctx); /* end vortex function */ vortex_exit_ctx (ctx, axl_true); return 0; }
int main (int argc, char ** argv) { /* create the context */ ctx = vortex_ctx_new (); /* init vortex library */ if (! vortex_init_ctx (ctx)) { /* unable to init context */ vortex_ctx_free (ctx); return -1; } /* end if */ /* register a profile */ vortex_profiles_register (ctx, COYOTE_PROFILE, start_channel, NULL, NULL, NULL, frame_received, NULL); /* create a vortex server */ vortex_listener_new (ctx, "0.0.0.0", "44000", on_ready, NULL); /* wait for listeners (until vortex_exit is called) */ vortex_listener_wait (ctx); /* do not call vortex_exit here if you define an on ready * function which actually ends the execution */ return 0; }
int main (int argc, char ** argv) { /* create the context */ ctx = vortex_ctx_new (); vortex_thread_pool_set_num (1); /* init vortex library */ if (! vortex_init_ctx (ctx)) { /* unable to init context */ vortex_ctx_free (ctx); return -1; } /* end if */ vortex_thread_pool_setup2 (ctx, 40, 1, 1, 1, 4, axl_true, axl_true); /* register a profile */ vortex_profiles_register (ctx, PLAIN_PROFILE, start_channel, NULL, close_channel, NULL, frame_received, NULL); /* create a vortex server */ vortex_listener_new (ctx, "0.0.0.0", "44000", NULL, NULL); /* configure connection notification */ vortex_listener_set_on_connection_accepted (ctx, on_accepted, NULL); /* wait for listeners (until vortex_exit is called) */ vortex_listener_wait (ctx); /* end vortex function */ vortex_exit_ctx (ctx, axl_true); return 0; }
int main (int argc, char ** argv) { /* the all frames received queue */ VortexAsyncQueue * queue; VortexFrame * frame; VortexChannel * channel; /* count */ int iterator = 0; /* create the context */ ctx = vortex_ctx_new (); /* init vortex library */ if (! vortex_init_ctx (ctx)) { /* unable to init context */ vortex_ctx_free (ctx); return -1; } /* end if */ /* create the queue */ queue = vortex_async_queue_new (); /* register a profile */ vortex_profiles_register (ctx, PROFILE_URI, /* no start handler, accept all channels */ NULL, NULL, /* no close channel, accept all * channels to be closed */ NULL, NULL, vortex_channel_queue_reply, queue); /* now create a vortex server listening on several ports */ vortex_listener_new (ctx, "0.0.0.0", "4400", NULL, NULL); /* and handle all frames received */ while (axl_true) { /* get the next message, blocking at this call. * * NOTE: This call must be evolved to something with * error handling, timeout and channel piggyback * support, but, for the example will do. */ frame = vortex_async_queue_pop (queue); if (frame == NULL) { /* for our example, the default action is: * keep on reading!. */ continue; } printf ("Frame received, content: %s\n", (char*) vortex_frame_get_payload (frame)); /* get the channel */ channel = vortex_frame_get_channel_ref (frame); /* reply */ vortex_channel_send_rpy (channel, vortex_frame_get_payload (frame), vortex_frame_get_payload_size (frame), vortex_frame_get_msgno (frame)); /* deallocate the frame received */ vortex_frame_free (frame); iterator++; /* close the channel */ if (iterator == 10) { /* close the channel */ if (! vortex_channel_close (channel, NULL)) { printf ("Unable to close the channel!\n"); } printf ("Ok, channel closed\n"); /* reset */ iterator = 0; } /* end if */ } /* end while */ /* end vortex internal subsystem (if no one have done it yet!) */ vortex_exit_ctx (ctx, axl_true); /* that's all to start BEEPing! */ return 0; }
/** * @brief Start the TMLCoreListener. */ int TMLCoreListener::TMLCoreListener_Start(const char* host, const char*port, const char** resPort) { int iRet = TML_SUCCESS; //tml_log(0xFFFFFFFF, "tmlCoreWrapper", "~tmlCoreWrapper", "POS", "Start-a"); if (!m_hValidListenerThread){ axl_bool bSuccess = axl_true; if (NULL == m_ctx){ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // create vortex execution context because the listener needs it's own // A reference from the tmlCoreWrapper don't work because the listener and the sender must work on the same platform m_log->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "TMLCoreListener_Start", "Vortex CMD", "vortex_ctx_new"); m_ctx = vortex_ctx_new (); ///////////////////////////////////////////////////////////// // init vortex library / SIDEX-72 has only to be done once m_log->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "TMLCoreListener_Start", "Vortex CMD", "vortex_init_ctx"); bSuccess = vortex_init_ctx (m_ctx); if (axl_true != bSuccess){ m_ctx = NULL; m_log->log ("TMLCoreListener", "TMLCoreListener;TMLCoreListener_Start", "vortex_init_ctx", "FAILLED"); iRet = TML_ERR_LISTENER_NOT_INITIALIZED; } } tmlListenerObj* listenerMngObj = NULL; TML_LISTENER_HANDLE listenerHandle = TML_HANDLE_TYPE_NULL; TML_BOOL bHasAnyListener = TML_FALSE; if (TML_SUCCESS == iRet){ bHasAnyListener = ((tmlCoreWrapper*)m_coreHandle)->tmlCoreWrapper_Has_Any_Listener(); if (!bHasAnyListener){ iRet = ((tmlCoreWrapper*)m_coreHandle)->tmlCoreWrapper_Listener_Create(host, port, &listenerHandle); } else{ iRet = ((tmlCoreWrapper*)m_coreHandle)->tmlCoreWrapper_Get_Listener(0, &listenerHandle); } if (TML_SUCCESS == iRet){ listenerMngObj = (tmlListenerObj*) listenerHandle; iRet = listenerMngObj->set_Enabled(TML_TRUE); if (TML_SUCCESS != iRet && !bHasAnyListener){ ((tmlCoreWrapper*)m_coreHandle)->tmlCoreWrapper_Listener_Close(&listenerHandle); } } } if (TML_SUCCESS == iRet){ ////////////////////////////////////////////////////////////// // in case of port equals 0 the vortex_listener_new will find // the next free port, so I want to know it's identification: m_log->log (TML_LOG_VORTEX_CMD, "TMLCoreListener", "TMLCoreListener_Start", "Vortex CMD", "vortex_connection_get_port"); iRet = listenerMngObj->getPort((char**)resPort); if (TML_SUCCESS != iRet){ if (!bHasAnyListener){ ((tmlCoreWrapper*)m_coreHandle)->tmlCoreWrapper_Listener_Close(&listenerHandle); } iRet = TML_ERR_LISTENER_NOT_INITIALIZED; } } if (TML_SUCCESS == iRet){ m_hValidListenerThread = true; } } else{ // Error / context already exists iRet = TML_ERR_LISTENER_ALREADY_STARTED; } return iRet; }