예제 #1
0
void KSG_Proactor_Handler::open(ACE_HANDLE new_handle
								  , ACE_Message_Block &message_block)
{
	ACE_DEBUG((LM_DEBUG,"打开连接 HANDLER[%d]",get_handler_id()));
	this->handle(new_handle);
	update_io_time();
	_can_be_closing = 1;
	if(_reader.open(*this) == -1 
		|| _writer.open(*this) == -1)
	{
		ACE_DEBUG((LM_ERROR,"打开 ACE 连接失败!!!"));
		free_handler();
		return;
	}
	char val[2] = "";
	int len = 1;
	val[0] = 0x1;
	//if(ACE_OS::setsockopt(new_handle,SOL_SOCKET,SO_OOBINLINE,val,len)==0)
	//	ACE_DEBUG((LM_INFO,"创建新连接,设置属性成功"));
	if(ACE_OS::setsockopt(new_handle,SOL_SOCKET,TCP_NODELAY,val,len)!=0)
		ACE_DEBUG((LM_ERROR,"创建新连接,设置属性失败"));

	on_open(new_handle,message_block);
	
	ACE_DEBUG((LM_DEBUG,"打开连接成功..."));
}
예제 #2
0
파일: hdsvr.cpp 프로젝트: nykma/ykt4sungard
void HD_CCU_Request_Handler::handle_read_stream(
    const ACE_Asynch_Read_Stream::Result &result)
{
    ACE_Message_Block & mb = result.message_block();
    if(!result.success() || result.bytes_transferred() == 0)
    {
        // 认为接收数据失败
        ACE_DEBUG((LM_ERROR,"读取 CCU 数据失败!!"));
        free_handler();
        return;
    }
    else
    {
        ACE_DEBUG((LM_DEBUG,"开始处理数据..."));
        // 读取数据完成
        ACE_InputCDR cdr(&mb);
        ACE_CDR::UShort data_len;
        cdr >> data_len;
        if(mb.length() - MSG_BUF_LEN_HEADER >= data_len )
        {
            // 读取完成,处理业务
            if( process_request(&mb)<= 0 )
            {
                // 处理失败或者不需要应答
                free_handler();
            }
            return;
        }
        // 认为数据有问题
        // 继续读取
        if(mb.length() >= 65535)
        {
            ACE_DEBUG((LM_ERROR,"数据包长度不合法!!!!"));
            free_handler();
            return;
        }
        ACE_DEBUG((LM_DEBUG,"继续读取数据..."));
        mb.wr_ptr(mb.length());
        if( _reader.read(mb
                         ,result.bytes_to_read() - result.bytes_transferred()) != 0)
        {
            ACE_DEBUG((LM_ERROR,"读取 CCU 数据失败!!"));
            free_handler();
            return;
        }
    }
}
예제 #3
0
void free_handlers(struct service_node *tp) {
  struct handler *hp, *lp;

  for(hp=tp->handlers;hp;) {
    lp = hp;
    hp = hp->next;
    free_handler(lp);
  }

  tp->handlers = NULL;
}
예제 #4
0
파일: hdsvr.cpp 프로젝트: nykma/ykt4sungard
void HD_CCU_Request_Handler::handle_write_stream(
    const ACE_Asynch_Write_Stream::Result &result)
{
    if(_request_handler)
    {
        _request_handler->DoFinish(handle());
    }
    // 释放资源
    //result.message_block().release();
    free_handler();
}
예제 #5
0
/* Allocate the handler of this plugin. */
static lsmas_handler_t *alloc_handler
(
    void
)
{
    lsmas_handler_t *hp = lw_malloc_zero( sizeof(lsmas_handler_t) );
    if( !hp )
        return NULL;
    hp->vdhp = libavsmash_video_alloc_decode_handler();
    if( !hp->vdhp )
    {
        free_handler( &hp );
        return NULL;
    }
    hp->vohp = libavsmash_video_alloc_output_handler();
    if( !hp->vohp )
    {
        free_handler( &hp );
        return NULL;
    }
    return hp;
}
예제 #6
0
void deregister_handler(struct handler *hl) {
  struct service_node *service = (struct service_node *)hl->service;  
  struct handler *np, *lp = NULL;
  for(np=service->handlers;np;lp=np,np=np->next) {
    if(hl == np) {
      if(lp) {
        lp->next = np->next;
      } else {
        service->handlers = np->next;
      }
      free_handler(np);
      return;
    }
  }
}
예제 #7
0
파일: qbuffer.c 프로젝트: aneeshd/ctcp
void
q_free(qbuffer_t* buff, void (*free_handler)(void*)){
  pthread_mutex_lock(&buff->q_mutex_);

  int i;
  for(i = buff->head; i > buff->tail; i--){
    free_handler(buff->q_[modulo(i, buff->max_size)]);
    buff->q_[modulo(i, buff->max_size)] = NULL;
  }

  buff->head = 0;
  buff->tail = 0;
  buff->size = 0;

  pthread_mutex_unlock(&buff->q_mutex_);
}
예제 #8
0
파일: hdsvr.cpp 프로젝트: nykma/ykt4sungard
int HD_CCU_Request_Handler::on_open(ACE_HANDLE new_handle
                                    , ACE_Message_Block &message_block)
{
    ACE_Message_Block *new_mb;
    ACE_NEW_NORETURN(new_mb,ACE_Message_Block(MAX_MESBUF_LEN));
    if(_reader.read(*new_mb,new_mb->space()) != 0)
    {
        int err = ACE_OS::last_error();
        ACE_DEBUG((LM_ERROR,"读取 CCU 连接数据失败![%d][%s]"
                   ,err,ACE_OS::strerror(err)));
        new_mb->release();
        free_handler();
        return -1;
    }
    _mblk = new_mb;
    return 0;
}
예제 #9
0
/* Allocate the handler of this plugin. */
static lwlibav_handler_t *alloc_handler
(
    void
)
{
    lwlibav_handler_t *hp = lw_malloc_zero( sizeof(lwlibav_handler_t) );
    if( !hp )
        return NULL;
    if( !(hp->vdhp = lwlibav_video_alloc_decode_handler())
     || !(hp->vohp = lwlibav_video_alloc_output_handler())
     || !(hp->adhp = lwlibav_audio_alloc_decode_handler())
     || !(hp->aohp = lwlibav_audio_alloc_output_handler()) )
    {
        free_handler( &hp );
        return NULL;
    }
    return hp;
}
예제 #10
0
static void
finalize (GObject *object)
{
	SoupServer *server = SOUP_SERVER (object);
	SoupServerPrivate *priv = SOUP_SERVER_GET_PRIVATE (server);
	GSList *iter;

	if (priv->interface)
		g_object_unref (priv->interface);

	g_free (priv->ssl_cert_file);
	g_free (priv->ssl_key_file);
	if (priv->ssl_creds)
		soup_ssl_free_server_credentials (priv->ssl_creds);

	g_free (priv->server_header);

	if (priv->listen_sock)
		g_object_unref (priv->listen_sock);

	while (priv->client_socks) {
		SoupSocket *sock = priv->client_socks->data;

		soup_socket_disconnect (sock);
		priv->client_socks =
			g_slist_remove (priv->client_socks, sock);
	}

	if (priv->default_handler)
		free_handler (priv->default_handler);
	soup_path_map_free (priv->handlers);

	for (iter = priv->auth_domains; iter; iter = iter->next)
		g_object_unref (iter->data);
	g_slist_free (priv->auth_domains);

	if (priv->loop)
		g_main_loop_unref (priv->loop);
	if (priv->async_context)
		g_main_context_unref (priv->async_context);

	G_OBJECT_CLASS (soup_server_parent_class)->finalize (object);
}
예제 #11
0
/**
 * soup_server_remove_handler:
 * @server: a #SoupServer
 * @path: the toplevel path for the handler
 *
 * Removes the handler registered at @path.
 **/
void
soup_server_remove_handler (SoupServer *server, const char *path)
{
	SoupServerPrivate *priv;
	SoupServerHandler *hand;

	g_return_if_fail (SOUP_IS_SERVER (server));
	priv = SOUP_SERVER_GET_PRIVATE (server);

	if (!path || !*path || !strcmp (path, "/")) {
		if (priv->default_handler) {
			unregister_handler (priv->default_handler);
			free_handler (priv->default_handler);
			priv->default_handler = NULL;
		}
		return;
	}

	hand = soup_path_map_lookup (priv->handlers, path);
	if (hand && !strcmp (path, hand->path)) {
		unregister_handler (hand);
		soup_path_map_remove (priv->handlers, path);
	}
}
예제 #12
0
int inthash_remove(inthash hashtable, const char *name) {
  int pos = (inthash_key(name) % hashtable->hash_size);
  inthash_chain **h = &hashtable->hash[pos];
  t_inthash_freehandler free_handler = NULL;

  if (hashtable->flag_valueismalloc) {
    if (hashtable->free_handler)
      free_handler = hashtable->free_handler;
    else
      free_handler = inthash_default_free_handler;
  }
  while(*h) {
    if (strcmp((*h)->name, name) == 0) {
      inthash_chain *next;

      if (free_handler) {
        if ((*h)->value.ptr) {
          void *ptr = (*h)->value.ptr;

          if (free_handler)
            free_handler(ptr);
          else
            freet(ptr);
          (*h)->value.ptr = 0;
        }
      }
      next = (*h)->next;
      freet(*h);
      *h = next;
      hashtable->nitems--;
      return 1;
    }
    h = &((*h)->next);
  }
  return 0;
}
예제 #13
0
void KSG_Proactor_Handler::handle_time_out(const ACE_Time_Value &tv
											 , const void *act /* = NULL */)
{
	ACE_DEBUG((LM_ERROR," HANDLER [%d]超时...",get_handler_id()));
	free_handler();
}
예제 #14
0
void VS_CC vs_libavsmashsource_create( const VSMap *in, VSMap *out, void *user_data, VSCore *core, const VSAPI *vsapi )
{
    /* Get file name. */
    const char *file_name = vsapi->propGetData( in, "source", 0, NULL );
    if( !file_name )
    {
        vsapi->setError( out, "lsmas: failed to get source file name." );
        return;
    }
    /* Allocate the handler of this plugin. */
    lsmas_handler_t *hp = alloc_handler();
    if( !hp )
    {
        vsapi->setError( out, "lsmas: failed to allocate the handler." );
        return;
    }
    libavsmash_video_decode_handler_t *vdhp = hp->vdhp;
    libavsmash_video_output_handler_t *vohp = hp->vohp;
    vs_video_output_handler_t *vs_vohp = vs_allocate_video_output_handler( vohp );
    if( !vs_vohp )
    {
        free_handler( &hp );
        vsapi->setError( out, "lsmas: failed to allocate the VapourSynth video output handler." );
        return;
    }
    vohp->private_handler      = vs_vohp;
    vohp->free_private_handler = lw_free;
    /* Set up VapourSynth error handler. */
    vs_basic_handler_t vsbh = { 0 };
    vsbh.out       = out;
    vsbh.frame_ctx = NULL;
    vsbh.vsapi     = vsapi;
    /* Set up log handler. */
    lw_log_handler_t lh = { 0 };
    lh.level    = LW_LOG_FATAL;
    lh.priv     = &vsbh;
    lh.show_log = set_error;
    /* Open source file. */
    uint32_t number_of_tracks = open_file( hp, file_name, &lh );
    if( number_of_tracks == 0 )
    {
        vs_filter_free( hp, core, vsapi );
        return;
    }
    /* Get options. */
    int64_t track_number;
    int64_t threads;
    int64_t seek_mode;
    int64_t seek_threshold;
    int64_t variable_info;
    int64_t direct_rendering;
    int64_t fps_num;
    int64_t fps_den;
    const char *format;
    const char *preferred_decoder_names;
    set_option_int64 ( &track_number,            0,    "track",          in, vsapi );
    set_option_int64 ( &threads,                 0,    "threads",        in, vsapi );
    set_option_int64 ( &seek_mode,               0,    "seek_mode",      in, vsapi );
    set_option_int64 ( &seek_threshold,          10,   "seek_threshold", in, vsapi );
    set_option_int64 ( &variable_info,           0,    "variable",       in, vsapi );
    set_option_int64 ( &direct_rendering,        0,    "dr",             in, vsapi );
    set_option_int64 ( &fps_num,                 0,    "fpsnum",         in, vsapi );
    set_option_int64 ( &fps_den,                 1,    "fpsden",         in, vsapi );
    set_option_string( &format,                  NULL, "format",         in, vsapi );
    set_option_string( &preferred_decoder_names, NULL, "decoder",        in, vsapi );
    set_preferred_decoder_names_on_buf( hp->preferred_decoder_names_buf, preferred_decoder_names );
    libavsmash_video_set_seek_mode              ( vdhp, CLIP_VALUE( seek_mode,      0, 2 ) );
    libavsmash_video_set_forward_seek_threshold ( vdhp, CLIP_VALUE( seek_threshold, 1, 999 ) );
    libavsmash_video_set_preferred_decoder_names( vdhp, tokenize_preferred_decoder_names( hp->preferred_decoder_names_buf ) );
    vohp->vfr2cfr = (fps_num > 0 && fps_den > 0);
    vohp->cfr_num = (uint32_t)fps_num;
    vohp->cfr_den = (uint32_t)fps_den;
    vs_vohp->variable_info               = CLIP_VALUE( variable_info,  0, 1 );
    vs_vohp->direct_rendering            = CLIP_VALUE( direct_rendering,  0, 1 ) && !format;
    vs_vohp->vs_output_pixel_format = vs_vohp->variable_info ? pfNone : get_vs_output_pixel_format( format );
    if( track_number && track_number > number_of_tracks )
    {
        vs_filter_free( hp, core, vsapi );
        set_error_on_init( out, vsapi, "lsmas: the number of tracks equals %"PRIu32".", number_of_tracks );
        return;
    }
    libavsmash_video_set_log_handler( vdhp, &lh );
    /* Get video track. */
    if( libavsmash_video_get_track( vdhp, track_number ) < 0 )
    {
        vs_filter_free( hp, core, vsapi );
        return;
    }
    /* Set up decoders for this track. */
    threads = threads >= 0 ? threads : 0;
    if( prepare_video_decoding( hp, threads, out, core, vsapi ) < 0 )
    {
        vs_filter_free( hp, core, vsapi );
        return;
    }
    lsmash_discard_boxes( libavsmash_video_get_root( vdhp ) );
    vsapi->createFilter( in, out, "LibavSMASHSource", vs_filter_init, vs_filter_get_frame, vs_filter_free, fmUnordered, nfMakeLinear, hp, core );
    return;
}
예제 #15
0
static void VS_CC vs_filter_free( void *instance_data, VSCore *core, const VSAPI *vsapi )
{
    free_handler( (lsmas_handler_t **)&instance_data );
}
예제 #16
0
void VS_CC vs_lwlibavsource_create( const VSMap *in, VSMap *out, void *user_data, VSCore *core, const VSAPI *vsapi )
{
    /* Get file path. */
    const char *file_path = vsapi->propGetData( in, "source", 0, NULL );
    if( !file_path )
    {
        vsapi->setError( out, "lsmas: failed to get source file name." );
        return;
    }
    /* Allocate the handler of this filter function. */
    lwlibav_handler_t *hp = alloc_handler();
    if( !hp )
    {
        vsapi->setError( out, "lsmas: failed to allocate the LW-Libav handler." );
        return;
    }
    lwlibav_file_handler_t         *lwhp = &hp->lwh;
    lwlibav_video_decode_handler_t *vdhp = hp->vdhp;
    lwlibav_video_output_handler_t *vohp = hp->vohp;
    vs_video_output_handler_t *vs_vohp = vs_allocate_video_output_handler( vohp );
    if( !vs_vohp )
    {
        free_handler( &hp );
        vsapi->setError( out, "lsmas: failed to allocate the VapourSynth video output handler." );
        return;
    }
    vohp->private_handler      = vs_vohp;
    vohp->free_private_handler = lw_free;
    /* Set up VapourSynth error handler. */
    vs_basic_handler_t vsbh = { 0 };
    vsbh.out       = out;
    vsbh.frame_ctx = NULL;
    vsbh.vsapi     = vsapi;
    /* Set up log handler. */
    lw_log_handler_t lh = { 0 };
    lh.level    = LW_LOG_FATAL;
    lh.priv     = &vsbh;
    lh.show_log = set_error;
    /* Get options. */
    int64_t stream_index;
    int64_t threads;
    int64_t cache_index;
    int64_t seek_mode;
    int64_t seek_threshold;
    int64_t variable_info;
    int64_t direct_rendering;
    int64_t fps_num;
    int64_t fps_den;
    int64_t apply_repeat_flag;
    int64_t field_dominance;
    const char *format;
    const char *preferred_decoder_names;
    set_option_int64 ( &stream_index,           -1,    "stream_index",   in, vsapi );
    set_option_int64 ( &threads,                 0,    "threads",        in, vsapi );
    set_option_int64 ( &cache_index,             1,    "cache",          in, vsapi );
    set_option_int64 ( &seek_mode,               0,    "seek_mode",      in, vsapi );
    set_option_int64 ( &seek_threshold,          10,   "seek_threshold", in, vsapi );
    set_option_int64 ( &variable_info,           0,    "variable",       in, vsapi );
    set_option_int64 ( &direct_rendering,        0,    "dr",             in, vsapi );
    set_option_int64 ( &fps_num,                 0,    "fpsnum",         in, vsapi );
    set_option_int64 ( &fps_den,                 1,    "fpsden",         in, vsapi );
    set_option_int64 ( &apply_repeat_flag,       0,    "repeat",         in, vsapi );
    set_option_int64 ( &field_dominance,         0,    "dominance",      in, vsapi );
    set_option_string( &format,                  NULL, "format",         in, vsapi );
    set_option_string( &preferred_decoder_names, NULL, "decoder",        in, vsapi );
    set_preferred_decoder_names_on_buf( hp->preferred_decoder_names_buf, preferred_decoder_names );
    /* Set options. */
    lwlibav_option_t opt;
    opt.file_path         = file_path;
    opt.threads           = threads >= 0 ? threads : 0;
    opt.av_sync           = 0;
    opt.no_create_index   = !cache_index;
    opt.force_video       = (stream_index >= 0);
    opt.force_video_index = stream_index >= 0 ? stream_index : -1;
    opt.force_audio       = 0;
    opt.force_audio_index = -1;
    opt.apply_repeat_flag = apply_repeat_flag;
    opt.field_dominance   = CLIP_VALUE( field_dominance, 0, 2 );    /* 0: Obey source flags, 1: TFF, 2: BFF */
    opt.vfr2cfr.active    = fps_num > 0 && fps_den > 0 ? 1 : 0;
    opt.vfr2cfr.fps_num   = fps_num;
    opt.vfr2cfr.fps_den   = fps_den;
    lwlibav_video_set_seek_mode              ( vdhp, CLIP_VALUE( seek_mode,      0, 2 ) );
    lwlibav_video_set_forward_seek_threshold ( vdhp, CLIP_VALUE( seek_threshold, 1, 999 ) );
    lwlibav_video_set_preferred_decoder_names( vdhp, tokenize_preferred_decoder_names( hp->preferred_decoder_names_buf ) );
    vs_vohp->variable_info          = CLIP_VALUE( variable_info,     0, 1 );
    vs_vohp->direct_rendering       = CLIP_VALUE( direct_rendering,  0, 1 ) && !format;
    vs_vohp->vs_output_pixel_format = vs_vohp->variable_info ? pfNone : get_vs_output_pixel_format( format );
    /* Set up progress indicator. */
    progress_indicator_t indicator;
    indicator.open   = NULL;
    indicator.update = NULL;
    indicator.close  = NULL;
    /* Construct index. */
    int ret = lwlibav_construct_index( lwhp, vdhp, vohp, hp->adhp, hp->aohp, &lh, &opt, &indicator, NULL );
    lwlibav_audio_free_decode_handler_ptr( &hp->adhp );
    lwlibav_audio_free_output_handler_ptr( &hp->aohp );
    if( ret < 0 )
    {
        vs_filter_free( hp, core, vsapi );
        set_error_on_init( out, vsapi, "lsmas: failed to construct index." );
        return;
    }
    /* Get the desired video track. */
    lwlibav_video_set_log_handler( vdhp, &lh );
    if( lwlibav_video_get_desired_track( lwhp->file_path, vdhp, lwhp->threads ) < 0 )
    {
        vs_filter_free( hp, core, vsapi );
        return;
    }
    /* Set average framerate. */
    hp->vi.numFrames = vohp->frame_count;
    hp->vi.fpsNum    = 25;
    hp->vi.fpsDen    = 1;
    lwlibav_video_setup_timestamp_info( lwhp, vdhp, vohp, &hp->vi.fpsNum, &hp->vi.fpsDen );
    /* Set up decoders for this stream. */
    if( prepare_video_decoding( hp, out, core, vsapi ) < 0 )
    {
        vs_filter_free( hp, core, vsapi );
        return;
    }
    vsapi->createFilter( in, out, "LWLibavSource", vs_filter_init, vs_filter_get_frame, vs_filter_free, fmUnordered, nfMakeLinear, hp, core );
    return;
}