Пример #1
0
void
tcp_manager::doRPC_tcp_connect_cb (RPC_delay_args *args, int fd)
{

  hostinfo *hi = lookup_host (args->l->address ());
  if (fd < 0) {
    warn << "locationtable: connect failed: " << strerror (errno) << "\n";
    (args->cb) (RPC_CANTSEND);
    args->l->set_alive (false);
    remove_host (hi);
    delete args;
  }
  else {
    struct linger li;
    li.l_onoff = 1;
    li.l_linger = 0;
    setsockopt (fd, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof (li));
    tcp_nodelay (fd);
    make_async(fd);
    hi->fd = fd;
    hi->xp = axprt_stream::alloc (fd);
    assert (hi->xp);
    send_RPC (args);
    while (hi->connect_waiters.size ())
      send_RPC (hi->connect_waiters.pop_front ());
  }
}
Пример #2
0
static int _tcp_nodelay(lua_State *L)
{
	int fd = luaL_checkint(L, 1);
	int keep_alive = lua_toboolean(L, 2);
	int ret = tcp_nodelay(fd, keep_alive);
	lua_pushinteger(L, ret);
	return 1;
}
Пример #3
0
proxy::proxy (int fd1, int fd2)
{
    con[0].fd = fd1;
    con[1].fd = fd2;
    for (int i = 0; i < 2; i++) {
        make_async (con[i].fd);
        tcp_nodelay (con[i].fd);
        setcb (i);
    }
}
Пример #4
0
 void
 acceptor_t::accept_impl (int fd, const str &s)
 {
   if (_verbose) {
     warn ("accepting connection from %s\n", s.cstr ());
   }
   tcp_nodelay (fd);
   ref<axprt_stream> x = axprt_stream::alloc (fd, _packet_sz);
   (*_cb) (x);
 }
Пример #5
0
static ptr<axprt_stream>
sfs_accept (bool primary, sfsserv_axprt_cb cb, int fd)
{
  if (fd < 0) {
    if (primary)
      (*cb) (NULL);
    return NULL;
  }
  tcp_nodelay (fd);
  ref<axprt_crypt> x = axprt_crypt::alloc (fd);
  return (*cb) (x);
}
Пример #6
0
Файл: net.cpp Проект: sga001/vex
// Accept an incoming TCP connection
void
net::tcp_accept(int tmp_socket, cbsb cb)
{
  struct sockaddr_in sin;
  uint32_t sinlen = sizeof(sin); 
 
  fd_ = accept(tmp_socket, (struct sockaddr*) &sin, &sinlen);
  
  tcp_nodelay(fd_);

  if (fd_ < 0 && errno != EAGAIN)
    fatal << "accept() failed. errno = " << errno << "\n";
  
  a_read(cb);
}
static void
newserv (int fd)
{
  sockaddr_in sin;
  bzero (&sin, sizeof (sin));
  socklen_t sinlen = sizeof (sin);
  int nfd = accept (fd, (sockaddr *) &sin, &sinlen);
  if (nfd >= 0) {
    close_on_exec (nfd);
    tcp_nodelay (nfd);
    ref<axprt_clone> x = axprt_clone::alloc (nfd);
    ref<asrv> s = asrv::alloc (x, sfs_program_1);
    s->setcb (wrap (sclone, s, x, sin));
  }
  else if (errno != EAGAIN)
    warn ("accept: %m\n");
}
Пример #8
0
Файл: net.cpp Проект: sga001/vex
// Make a new TCP connection (this blocks)
void
net::tcp_connect(str host, int port) 
{
	int ret;
  int flag;
  struct sockaddr_in sin;

	// Get socket
	fd_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	check_ret(fd_, "socket()");

  // Disable Nagle buffering algorithm
  tcp_nodelay(fd_);

	// Zero structure
	memset(&sin, 0, sizeof(sin));

	// Set to IPV4
	sin.sin_family = AF_INET;
	
	// Convert address
	ret = inet_pton(AF_INET, host.cstr(), &sin.sin_addr.s_addr);
	check_ret(ret, "inet_pton()");

	// Set port
	sin.sin_port = htons(port);
	
	// Establish connection to the server
	ret = connect(fd_, (struct sockaddr*) &sin, sizeof(sin));
	check_ret(ret, "connect()");	

  // Make fd asynchronous
  make_async(fd_); 

	// We are done
}