コード例 #1
0
ファイル: kbd.c プロジェクト: Efreak/elinks
/** A select_handler_T write_func for itrm_out.sock.  This is called
 * when there is data in @c itrm->out.queue and it is possible to write
 * it to @c itrm->out.sock.  When @c itrm->out.queue becomes empty, this
 * handler is temporarily removed.  */
static void
itrm_queue_write(struct itrm *itrm)
{
	int written;
	int qlen = int_min(itrm->out.queue.len, 128);

	assertm(qlen, "event queue empty");
	if_assert_failed return;

	written = safe_write(itrm->out.sock, itrm->out.queue.data, qlen);
	if (written <= 0) {
		if (written < 0) free_itrm(itrm); /* write error */
		return;
	}

	itrm->out.queue.len -= written;

	if (itrm->out.queue.len == 0) {
		set_handlers(itrm->out.sock,
			     get_handler(itrm->out.sock, SELECT_HANDLER_READ),
			     NULL,
			     get_handler(itrm->out.sock, SELECT_HANDLER_ERROR),
			     get_handler(itrm->out.sock, SELECT_HANDLER_DATA));
	} else {
		assert(itrm->out.queue.len > 0);
		memmove(itrm->out.queue.data, itrm->out.queue.data + written, itrm->out.queue.len);
	}
}
コード例 #2
0
ファイル: base_socket.cpp プロジェクト: RivenZoo/revolver
int32_t CBaseSocket::get_option(int level, int option, void *optval, int *optlen) const
{
#ifdef WIN32
	return getsockopt(get_handler(), level, option, (char *)optval, optlen);
#else
	return getsockopt(get_handler(), level, option, (char *)optval, (socklen_t *)optlen);
#endif
}
コード例 #3
0
ファイル: game.hpp プロジェクト: hamazy/shiritori
	virtual ~request_handlers()
	{
		std::for_each(
			boost::make_transform_iterator(request_handlers_.begin(), get_spec()),
			boost::make_transform_iterator(request_handlers_.end(), get_spec()),
			std::default_delete<request_spec>());
		std::for_each(
			boost::make_transform_iterator(request_handlers_.begin(), get_handler()),
			boost::make_transform_iterator(request_handlers_.end(), get_handler()),
			std::default_delete<request_handler>());
	}
コード例 #4
0
ファイル: base_socket.cpp プロジェクト: RivenZoo/revolver
int32_t CBaseSocket::recv(void *buf, uint32_t buf_size)
{
	if(!isopen())
		return -1;

	return ::recv(get_handler(), (char *)buf, buf_size, 0);
}
コード例 #5
0
ファイル: base_socket.cpp プロジェクト: RivenZoo/revolver
int32_t CBaseSocket::send(const void *buf, uint32_t buf_size)
{
	if(!isopen())
		return -1;

	return ::send(get_handler(), (const char *)buf, buf_size, 0);
}
コード例 #6
0
ファイル: accepter.c プロジェクト: BrianOn99/molamola-ftp
void *dedicated_serve(void *p)
{
        int sockfd = *((int*)p);
        if (wait_authenicated(sockfd) == -1) {
                printf("authenication has problem\n");
                close_serving_thread(sockfd);
        }

        /* now it is authenicated */
        struct message_s head_recv;

        while (1) {
                read_head_C(sockfd, &head_recv);
                req_handler handler = get_handler(head_recv.type);
                printf("Received request: %02x\n", head_recv.type);
                if (!handler) {
                        fprintf(stderr, "Request %02x is malformmated\n", head_recv.type);
                        continue;
                }
                handler(sockfd, &head_recv);
        }
        /* reach head means client closed */
        printf("closed connection\n");
        close_serving_thread(sockfd);
        return NULL;
}
コード例 #7
0
ファイル: linux32_sandbox.c プロジェクト: wuyihao14/bintools
enum __ptrace_request trace(pid_t pid, struct Handler* handler){
    unsigned ip, esp, ret;
    struct user_regs_struct regs;
    char inst_str[128];
    int len;
    Ptrace(PTRACE_GETREGS, pid, NULL, &regs);
    ip = regs.eip;
    // if ip is within a visible module. Output and trace on
    if (visible(ip, handler->option->trace_option.whitelist)){
        fprintf(handler->option->trace_option.file, "0x%x\n", ip);
        fflush(handler->option->trace_option.file);

        len = get_single_instruction_at(pid, ip, inst_str, 128);
        if (!strncmp(inst_str, "call", 4)){
            // If 'call', record the latest 'ret' addr
            get_global_handler(pid, ip + len, handler->option);
        }else{
            // If not 'call', hand on the latest 'ret' addr
            get_global_handler(pid, handler->ip, handler->option);
        }
        return PTRACE_SINGLESTEP;
    }else{
    // If not, run until the latest 'ret' addr
        get_handler(pid, handler->ip, handler->option);
        return PTRACE_CONT;
    }
}
コード例 #8
0
ファイル: base_socket.cpp プロジェクト: RivenZoo/revolver
int32_t CBaseSocket::send(const void* buf, uint32_t buf_size, const Inet_Addr& remote_addr)
{
	if(!isopen())
		return -1;

	return ::sendto(get_handler(), (const char *)buf, buf_size, 0, (struct sockaddr *)remote_addr.get_addr(), sizeof(sockaddr_in));
}
コード例 #9
0
ファイル: kbd.c プロジェクト: Efreak/elinks
void
itrm_queue_event(struct itrm *itrm, unsigned char *data, int len)
{
	int w = 0;

	if (!len) return;

	if (!itrm->out.queue.len && can_write(itrm->out.sock)) {
		w = safe_write(itrm->out.sock, data, len);
		if (w <= 0 && HPUX_PIPE) {
			register_bottom_half(free_itrm, itrm);
			return;
		}
	}

	if (w < len) {
		int left = len - w;
		unsigned char *c = mem_realloc(itrm->out.queue.data,
					       itrm->out.queue.len + left);

		if (!c) {
			free_itrm(itrm);
			return;
		}

		itrm->out.queue.data = c;
		memcpy(itrm->out.queue.data + itrm->out.queue.len, data + w, left);
		itrm->out.queue.len += left;
		set_handlers(itrm->out.sock,
			     get_handler(itrm->out.sock, SELECT_HANDLER_READ),
			     (select_handler_T) itrm_queue_write,
			     (select_handler_T) free_itrm, itrm);
	}
}
コード例 #10
0
ファイル: handler.c プロジェクト: NVIDIA/ptp-nsight
/*
 * Generate file descriptor sets
 */
void
GenerateFDSets(int *nfds, fd_set *rfds, fd_set *wfds, fd_set *efds)
{
	handler *	h;
	
	*nfds = 0;
	FD_ZERO(rfds);
	FD_ZERO(wfds);
	FD_ZERO(efds);
	
	for (set_handler(); (h = get_handler()) != NULL; ) {
		if (IS_FILE_HANDLER(h) && !IS_DISPOSED(h)) {
			if (IS_FILE_READ_HANDLER(h)) {
				FD_SET(h->fd, rfds);
			}
			if (IS_FILE_WRITE_HANDLER(h)) {
				FD_SET(h->fd, wfds);
			}
			if (IS_FILE_EXCEPT_HANDLER(h)) {
				FD_SET(h->fd, efds);
			}
			if (h->fd > *nfds) {
				*nfds = h->fd;
			}
		}
	}
}
コード例 #11
0
ファイル: smart_ptr.C プロジェクト: juddy/edcde
int smart_ptr::get_int(int i)
{
   handler* x = get_handler(i, INTEGER_CODE);
   int y= (*(integer_handler*)x) -> get();
   delete x;

   return y;
}
コード例 #12
0
ファイル: smart_ptr.C プロジェクト: juddy/edcde
oid_t smart_ptr::get_oid(int i)
{
   handler* x = get_handler(i, OID_CODE);
   oid_t y = (*(oid_handler*)x) -> my_coid();
   delete x;

   return y;
}
コード例 #13
0
/*
 * Main IOCTl dispatcher. Called from the main networking code
 * (dev_ioctl() in net/core/dev.c).
 * Check the type of IOCTL and call the appropriate wrapper...
 */
int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
{
	struct net_device *dev;
	iw_handler	handler;

	/* Permissions are already checked in dev_ioctl() before calling us.
	 * The copy_to/from_user() of ifr is also dealt with in there */

	/* Make sure the device exist */
	if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
		return -ENODEV;

	/* A bunch of special cases, then the generic case...
	 * Note that 'cmd' is already filtered in dev_ioctl() with
	 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
	switch(cmd) 
	{
		case SIOCGIWSTATS:
			/* Get Wireless Stats */
			return dev_iwstats(dev, ifr);

		case SIOCGIWPRIV:
			/* Check if we have some wireless handlers defined */
			if(dev->wireless_handlers != NULL) {
				/* We export to user space the definition of
				 * the private handler ourselves */
				return ioctl_export_private(dev, ifr);
			}
			// ## Fall-through for old API ##
		default:
			/* Generic IOCTL */
			/* Basic check */
			if (!netif_device_present(dev))
				return -ENODEV;
			/* New driver API : try to find the handler */
			handler = get_handler(dev, cmd);
			if(handler != NULL) {
				/* Standard and private are not the same */
				if(cmd < SIOCIWFIRSTPRIV)
					return ioctl_standard_call(dev,
								   ifr,
								   cmd,
								   handler);
				else
					return ioctl_private_call(dev,
								  ifr,
								  cmd,
								  handler);
			}
			/* Old driver API : call driver ioctl handler */
			if (dev->do_ioctl) {
				return dev->do_ioctl(dev, ifr, cmd);
			}
			return -EOPNOTSUPP;
	}
	/* Not reached */
	return -EINVAL;
}
コード例 #14
0
ファイル: ngfif.c プロジェクト: matthewvogt/ngfd
int ngfif_handle_stop_request(struct tonegend *t, NRequest *request)
{
    struct event_handler *handler;

    if (!(handler = get_handler(t, get_type(request))))
        return FALSE;

    return handler->method_stop_cb ? handler->method_stop_cb(request, t) : 0;
}
コード例 #15
0
ファイル: ngfif.c プロジェクト: matthewvogt/ngfd
int ngfif_handle_start_request(struct tonegend *t, NRequest *request)
{
    struct event_handler *handler;

    if ((handler = get_handler(t, get_type(request))))
        return handler->method_start_cb(request, t);
    else
        return FALSE;
}
コード例 #16
0
ファイル: ngfif.c プロジェクト: matthewvogt/ngfd
int ngfif_can_handle_request(struct tonegend *t, NRequest *request)
{
    const char *event_type;

    if ((event_type = get_type(request))) {
        if (get_handler(t, event_type))
            return TRUE;
    }

    return FALSE;
}
コード例 #17
0
ファイル: user.cpp プロジェクト: ATNoG/EMICOM
/**
 * Sent message handler. After sending the message, this function is called to
 * report the success or failure in delivering the message to the local MIHF.
 *
 * @param fm MIH message sent.
 * @param h Message handler.
 * @param ec Error code.
 */
void user::send_handler(mih::frame_vla& fm, handler& h, const boost::system::error_code& ec)
{
	if (ec && !h)
		get_handler(fm->tid(), h);

	if (h) {
		mih::message pm(*fm);

		h(pm, ec);
	}
}
コード例 #18
0
ファイル: eject.c プロジェクト: xutian/C_Study
static BOOL close_cdrom(WCHAR drive)
{
    HANDLE handle;
    BOOL ret;

    handle = get_handler(drive);
    ret = cdrom_io_control(handle, IOCTL_STORAGE_LOAD_MEDIA, NULL);
    close_handler(handle);

    return ret;
}
コード例 #19
0
ファイル: handler.c プロジェクト: NVIDIA/ptp-nsight
/**
 * Unregister file descriptor handler
 * Can be called from callback function.
 */
void
UnregisterFileHandler(int fd)
{
	handler *	h;

	for (set_handler(); (h = get_handler()) != NULL; ) {
		if (IS_FILE_HANDLER(h) && h->fd == fd) {
			h->htype |= HANDLER_DISPOSED;
		}
	}
}
コード例 #20
0
ファイル: eject.c プロジェクト: xutian/C_Study
static BOOL unlock_cdrom(WCHAR drive)
{
    HANDLE handle;
    PREVENT_MEDIA_REMOVAL removal;
    removal.PreventMediaRemoval = FALSE;

    handle = get_handler(drive);
    cdrom_io_control(handle, IOCTL_STORAGE_MEDIA_REMOVAL, &removal);
    close_handler(handle);

    return TRUE;
}
コード例 #21
0
ファイル: base_socket.cpp プロジェクト: RivenZoo/revolver
int32_t CBaseSocket::recv(void* buf, uint32_t buf_size, Inet_Addr& remote_addr)
{
	if(!isopen())
		return -1;

#ifdef WIN32
	int32_t from_size = sizeof(struct sockaddr_in);
#else
	uint32_t from_size = sizeof(struct sockaddr_in);
#endif

	return ::recvfrom(get_handler(), (char *)buf, buf_size, 0, (struct sockaddr *)remote_addr.get_addr(), &from_size);
}
コード例 #22
0
ファイル: handler.c プロジェクト: NVIDIA/ptp-nsight
/**
 * Unregister file descriptor handler.
 * Can be called from callback function.
 */
void
UnregisterEventHandler(int type, void (*event_callback)(void *, void *))
{
	handler *	h;

	for (set_handler(); (h = get_handler()) != NULL; ) {
		if (IS_EVENT_HANDLER(h)
				&& h->event_type == type
				&& h->event_handler == event_callback) {
			h->htype |= HANDLER_DISPOSED;
		}
	}
}
コード例 #23
0
ファイル: base_socket.cpp プロジェクト: RivenZoo/revolver
int32_t CBaseSocket::get_local_addr(Inet_Addr &local_addr) const
{
#ifdef WIN32
	int32_t len = sizeof(sockaddr_in);
#else
	uint32_t len = sizeof(sockaddr_in);
#endif

	  sockaddr *addr = reinterpret_cast<sockaddr *> (local_addr.get_addr());
	if(::getsockname(get_handler(), addr, &len) == -1)
		return -1;

	return 0;
}
コード例 #24
0
ファイル: smart_ptr.C プロジェクト: juddy/edcde
void smart_ptr::update_oid(int i, const oid_t& x)
{
   static char buf[64];

   handler* z = get_handler(i, OID_CODE);
   oid_handler* y = (oid_handler*)z;

   snprintf(buf, sizeof(buf), "%d.%d\n", x.ccode(), (int)x.icode());
   istringstream in(buf);

   (*y) -> asciiIn(in);

   delete y;
}
コード例 #25
0
ファイル: eject.c プロジェクト: xutian/C_Study
static BOOL eject_cdrom(WCHAR drive)
{
    HANDLE handle;
    PREVENT_MEDIA_REMOVAL removal;
    removal.PreventMediaRemoval = FALSE;

    handle = get_handler(drive);
    cdrom_io_control(handle, FSCTL_DISMOUNT_VOLUME, NULL);
    cdrom_io_control(handle, IOCTL_STORAGE_MEDIA_REMOVAL, &removal);
    cdrom_io_control(handle, IOCTL_STORAGE_EJECT_MEDIA, NULL);
    close_handler(handle);

    return TRUE;
}
コード例 #26
0
ファイル: nanosleep.c プロジェクト: AblePear/wget_pkg
int
nanosleep (const struct timespec *requested_delay,
           struct timespec *remaining_delay)
{
  static bool initialized;

  if (requested_delay->tv_nsec < 0 || BILLION <= requested_delay->tv_nsec)
    {
      errno = EINVAL;
      return -1;
    }

  /* set up sig handler */
  if (! initialized)
    {
      struct sigaction oldact;

      sigaction (SIGCONT, NULL, &oldact);
      if (get_handler (&oldact) != SIG_IGN)
        {
          struct sigaction newact;

          newact.sa_handler = sighandler;
          sigemptyset (&newact.sa_mask);
          newact.sa_flags = 0;
          sigaction (SIGCONT, &newact, NULL);
        }
      initialized = true;
    }

  suspended = 0;

  if (my_usleep (requested_delay) == -1)
    {
      if (suspended)
        {
          /* Calculate time remaining.  */
          /* FIXME: the code in sleep doesn't use this, so there's no
             rush to implement it.  */

          errno = EINTR;
        }
      return -1;
    }

  /* FIXME: Restore sig handler?  */

  return 0;
}
コード例 #27
0
void dump_op(zend_op *op, int num){
	static char buffer_op1[BUFFER_LEN];
	static char buffer_op2[BUFFER_LEN];
	static char buffer_result[BUFFER_LEN];
    format_znode(&op->op1, buffer_op1);
    format_znode(&op->op2, buffer_op2);
    format_znode(&op->result, buffer_result);
	printf("%6d|%6d|%20s|%50s|%10s|%10s|%6s|\n", num, op->lineno,
			opname(op->opcode),
            get_handler(op),
			buffer_op1,
			buffer_op2,
			buffer_result
            ) ;
}
コード例 #28
0
ファイル: handler.c プロジェクト: NVIDIA/ptp-nsight
/**
 * Call all event handlers of a particular type
 */
void
CallEventHandlers(int type, void *data)
{
	handler *	h;

	for (set_handler(); (h = get_handler()) != NULL; ) {
		if (IS_EVENT_HANDLER(h)) {
			if (IS_DISPOSED(h)) {
				dispose_handler(h);
			} else if (h->event_type == type) {
				h->event_handler(h->data, data);
			}
		}
	}
}
コード例 #29
0
ファイル: api.cpp プロジェクト: Aprilara/dplyr
    bool CallProxy::simplified(const SlicingIndex& indices){
        // initial
        if( TYPEOF(call) == LANGSXP ){
            boost::scoped_ptr<Result> res( get_handler(call, subsets, env) );

            if( res ){
                // replace the call by the result of process
                call = res->process(indices) ;

                // no need to go any further, we simplified the top level
                return true ;
            }

            return replace( CDR(call), indices ) ;

        }
        return false ;
    }
コード例 #30
0
ファイル: user.cpp プロジェクト: ATNoG/EMICOM
/**
 * Received message callback. This function is executed to process the
 * received messages. If this is a valid message, the message is
 * dispatched to the handler defined by the user.
 *
 * @param buff Message byte buffer.
 * @param rbytes Size of the message.
 * @param ec Error code.
 */
void user::recv_handler(buffer<uint8>& buff, size_t rbytes, const boost::system::error_code& ec)
{
	if (ec) {
		mih::message pm;

		_handler(pm, ec);

	} else {
		mih::frame* fm = mih::frame::cast(buff.get(), rbytes);

		if (fm) {
			mih::message pm(*fm);

			if (fm->opcode() == mih::operation::confirm) {
				handler h;

				get_handler(fm->tid(), h);
				if (h) {
					h(pm, ec);
				// Unsolicited MIH capability discover reception
				} else if(fm->sid() == mih::service::management &&
				        fm->aid() == mih::action::capability_discover) {
					_handler(pm, ec);
				} else {
					_handler(pm, boost::system::errc::make_error_code(boost::system::errc::bad_message));
				}
			} else if (fm->opcode() != mih::operation::indication) {
				_handler(pm, boost::system::errc::make_error_code(boost::system::errc::bad_message));
			} else {
				_handler(pm, ec);
			}
		}
	}

	void* rbuff = buff.get();
	size_t rlen = buff.size();

	_sock.async_receive(boost::asio::buffer(rbuff, rlen),
						boost::bind(&user::recv_handler,
									this,
									bind_rv(buff),
									boost::asio::placeholders::bytes_transferred,
									boost::asio::placeholders::error));
}