Esempio n. 1
0
/**
 * Fetches a channel object by name.
 * @param string Channel name.
 * @returns [bool] found, [LUD] channel object
 */
int LuaChannel::getChannel(lua_State* L) {
    luaL_checkany(L, 1);

    string channame = luaL_checkstring(L, 1);
    lua_pop(L, 1);
    ChannelPtr chan = ServerState::getChannel(channame);
    if (chan == 0) {
        lua_pushboolean(L, false);
        return 1;
    }
    lua_pushboolean(L, true);
    lua_pushlightuserdata(L, chan.get());
    return 2;
}
Esempio n. 2
0
int  EPoll::update(int operation, const ChannelPtr& channel)
{

	for(ChannelMap::iterator it=channelMap_.begin();it!=channelMap_.end();it++){
		std::cout<<"it :"<<it->first<<"\n";
	
	}	
  ChannelMap::iterator it = channelMap_.find(channel->get_fd());
  if (it == channelMap_.end()) 
  {
		std::cout<<"no find\n";
		return -2;
	}
  channelMap_[channel->get_fd()] = channel;
  struct epoll_event event;
  bzero(&event, sizeof event);
  event.events = channel->get_events();//要监听的事件,读,写等
  event.data.ptr =  static_cast<void*>( channel.get());//这样写返回时,直接获取channel,
  if (::epoll_ctl(epollfd_, operation,channel->get_fd(), &event) < 0)//EPOLL_CTL_ADD, EPOLL_CTL_MOD,EPOLL_CTL_DEL
  {
	
	std::cout<<epollfd_<<":"<<channel->get_fd()<<std::endl;
	std::cout<<"epoll_ctl error \n";
	std::cout<<strerror(errno)<<std::endl;
	exit(0);
    if (operation == EPOLL_CTL_DEL)
    {
    	;
    }
    else
    {
  	;
    }
    return 1;
  }
  return 0;
}