コード例 #1
0
ファイル: retr_opt.c プロジェクト: scalp42/my_ftp
int		init_download(client_ftp_t *client_ftp, char *cmd)
{
  char		buff[1024];
  int		i;

  bzero(buff, 1024);
  xsend(client_ftp->s, "TYPE I\n", 7, 0);
  i = xrecv(client_ftp->s, buff, 1024, 0);
  clean_buff(buff, i);
  printf("%s\n", buff);
  bzero(buff, 1024);
  open_new_data_connection(client_ftp);
  open_data_connection(client_ftp);
  bzero(buff, 1024);
  for (i = 4; cmd[i] == ' ' && cmd[i] != '\0'; i++)
    ;
  sprintf(buff, "RETR %s\n", cmd + i);
  xsend(client_ftp->s, buff, strlen(buff), 0);
  i = xrecv(client_ftp->s, buff, 1024, 0);
  clean_buff(buff, i);
  printf("%s\n", buff);
  if (strncmp(buff, "550", 3) == 0)
    {
      close(client_ftp->s_data);
      return (1);
    }
  return (0);
}
コード例 #2
0
ファイル: socket_base.cpp プロジェクト: bluig/zeromq2
int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_)
{
    //  Process pending commands, if any.
    if (unlikely (!app_thread->process_commands (false, true))) {
        errno = ETERM;
        return -1;
    }

    //  At this point we impose the MORE flag on the message.
    if (flags_ & ZMQ_SNDMORE)
        msg_->flags |= ZMQ_MSG_MORE;

    //  Try to send the message.
    int rc = xsend (msg_, flags_);
    if (rc == 0)
        return 0;

    //  In case of non-blocking send we'll simply propagate
    //  the error - including EAGAIN - upwards.
    if (flags_ & ZMQ_NOBLOCK)
        return -1;

    //  Oops, we couldn't send the message. Wait for the next
    //  command, process it and try to send the message again.
    while (rc != 0) {
        if (errno != EAGAIN)
            return -1;
        if (unlikely (!app_thread->process_commands (true, false))) {
            errno = ETERM;
            return -1;
        }
        rc = xsend (msg_, flags_);
    }
    return 0;
}
コード例 #3
0
ファイル: req_get.c プロジェクト: canercandan/another-ftp
int		req_get(t_cmd *c, t_req *r)
{
  struct stat	sb;
  char		buf[1024];
  char		*content;
  int		nbr;
  int		fd;

  if (DEBUG)
    printf("req_get()\n");
  if ((fd = open(c->param, O_RDONLY)) < 0)
    {
      close(fd);
      return (FALSE);
    }
  fstat(fd, &sb);
  sprintf(buf, "%s %s %d\r\n", r->req, c->param, (int) sb.st_size);
  xsend(c->f->cs, buf, (void *) strlen(buf), 0);
  content = malloc(sb.st_size);
  while ((nbr = read(fd, buf, sizeof(buf))) > 0)
    strncat(content, buf, nbr);
  xsend(c->f->cs, content, (void *) (int) sb.st_size, 0);
  /*free(content);*/
  close(fd);
  return (TRUE);
}
コード例 #4
0
void		send_players(t_env *env)
{
  int		pos;
  char		tmp[BUF_SIZE];

  pos = env->nb_team;
  while (pos < MAXCLIENT + 5)
    {
      if (env->clt[pos].level && env->clt[pos].state == alive && env->clt[pos].inteam)
	{
	  sprintf(tmp, "pnw %i %i %i %i %i %i\n", env->clt[pos].num_client,
		  env->clt[pos].posx, env->clt[pos].posy, DIR(env->clt[pos].dir),
		  env->clt[pos].level, env->clt[pos].num_team);
	  xsend(env->cs_graphic, tmp, strlen(tmp), "player");
	}
      pos++;
    }
  pos = 0;
  while (pos < MAXCLIENT + 5)
    if (env->clt[pos++].state == inegg)
      {
	sprintf(tmp, "enw %i %i %i %i\n", env->clt[pos - 1].num_client_egg,
		env->clt[pos - 1].num_client, env->clt[pos - 1].posx,
		env->clt[pos - 1].posy);
	xsend(env->cs_graphic, tmp, strlen(tmp), "player");
      }
}
コード例 #5
0
ファイル: device.c プロジェクト: fcondolo/rocket
int sync_update(struct sync_device *d, int row, struct sync_cb *cb,
    void *cb_param)
{
	if (d->sock == INVALID_SOCKET)
		return -1;

	/* look for new commands */
	while (socket_poll(d->sock)) {
		unsigned char cmd = 0, flag;
		uint32_t new_row;
		if (xrecv(d->sock, (char *)&cmd, 1, 0))
			goto sockerr;

		switch (cmd) {
		case SET_KEY:
			if (handle_set_key_cmd(d->sock, d))
				goto sockerr;
			break;
		case DELETE_KEY:
			if (handle_del_key_cmd(d->sock, d))
				goto sockerr;
			break;
		case SET_ROW:
			if (xrecv(d->sock, (char *)&new_row, sizeof(new_row), 0))
				goto sockerr;
			if (cb && cb->set_row)
				cb->set_row(cb_param, ntohl(new_row));
			break;
		case PAUSE:
			if (xrecv(d->sock, (char *)&flag, 1, 0))
				goto sockerr;
			if (cb && cb->pause)
				cb->pause(cb_param, flag);
			break;
		case SAVE_TRACKS:
			sync_save_tracks(d);
			break;
		default:
			fprintf(stderr, "unknown cmd: %02x\n", cmd);
			goto sockerr;
		}
	}

	if (cb && cb->is_playing && cb->is_playing(cb_param)) {
		if (d->row != row && d->sock != INVALID_SOCKET) {
			unsigned char cmd = SET_ROW;
			uint32_t nrow = htonl(row);
			if (xsend(d->sock, (char*)&cmd, 1, 0) ||
			    xsend(d->sock, (char*)&nrow, sizeof(nrow), 0))
				goto sockerr;
			d->row = row;
		}
	}
	return 0;

sockerr:
	closesocket(d->sock);
	d->sock = INVALID_SOCKET;
	return -1;
}
コード例 #6
0
ファイル: fct_cd.c プロジェクト: scalp42/my_ftp
void		send_cd_on_sock(client_ftp_t *client_ftp, char *real_path)
{
  client_ftp->pwd = strdup(real_path);
  if ((strncmp(client_ftp->pwd, client_ftp->pwd_init, strlen(client_ftp->pwd_init)) != 0) ||
      (chdir(client_ftp->pwd)) == -1)
    xsend(client_ftp->cs, NOPATH, strlen(NOPATH), 0);
  else
    xsend(client_ftp->cs, PATH, strlen(PATH), 0);
}
コード例 #7
0
ファイル: gauche.c プロジェクト: MagellanOo/xXxJUSTINBIBERxXx
void		do_droite(t_env *env, int cs)
{
  env->clt[cs].dir = ((env->clt[cs].dir == 3) ? (0) : (env->clt[cs].dir + 1));
  sprintf(env->clt[cs].buf_write, "ppo %i %i %i %i\n", env->clt[cs].num_client,
	  env->clt[cs].posx, env->clt[cs].posy, DIR(env->clt[cs].dir));
  xsend(env->cs_graphic, env->clt[cs].buf_write, strlen(env->clt[cs].buf_write)
	, "avance");
  xsend(cs, "ok\n", 3, "ok\n");
}
コード例 #8
0
ファイル: poll_ts.c プロジェクト: tniuli/xio
int main (int argc, char **argv)
{
	int i, j;
	char *ubuf = 0;
	int afd, sfd, tmp;
	thread_t cli_thread = {};

	BUG_ON ( (afd = xlisten ("tcp+ipc+inproc://127.0.0.1:18897") ) < 0);
	thread_start (&cli_thread, xclient_thread, 0);
	usleep (100000);
	BUG_ON (xselect (XPOLLIN, 1, &afd, 1, &tmp) <= 0);
	for (j = 0; j < 3; j++) {
		BUG_ON ( (sfd = xaccept (afd) ) < 0);
		for (i = 0; i < cnt; i++) {
			while (xselect (XPOLLIN, 1, &sfd, 1, &tmp) <= 0)
				usleep (10000);
			BUG_ON (tmp != sfd);
			BUG_ON (0 != xrecv (sfd, &ubuf) );
			BUG_ON (0 != xsend (sfd, ubuf) );
		}
		xclose (sfd);
	}
	thread_stop (&cli_thread);
	xclose (afd);
	return 0;
}
コード例 #9
0
ファイル: req_noop.c プロジェクト: canercandan/another-ftp
int	req_noop(t_cmd *c, t_req *r)
{
    r = 0;
    if (DEBUG)
        printf("req_noop()\n");
    xsend(c->f->cs, "", (void *) 1, 0);
    return (0);
}
コード例 #10
0
ファイル: fct_pwd.c プロジェクト: scalp42/my_ftp
void	fct_pwd(char __UNUSED__ *cmd, client_ftp_t *client_ftp, ftp_t __UNUSED__ *ftp)
{
    char	path[1024];

    memset(path, '\0', 1024);
    sprintf(path, PWD, client_ftp->pwd);
    xsend(client_ftp->cs, path, strlen(path), 0);
}
コード例 #11
0
void	init_graph(t_env *env, int cs)
{
  env->clt[cs].type = FD_GRAPH;
  env->cs_graphic = cs;
  env->clt[cs].g = 2;
  env->first = 1;
  sprintf(env->clt[cs].buf_write, "msz %i %i\n",
	  env->xwidth, env->ylength);
  xsend(env->cs_graphic, env->clt[cs].buf_write,
	strlen(env->clt[cs].buf_write), "G");
  sprintf(env->clt[cs].buf_write, "sgt %i\n",
	  (int)(env->timeunity));
  xsend(env->cs_graphic, env->clt[cs].buf_write,
	strlen(env->clt[cs].buf_write), "G");
  send_map(env);
  send_team(env);
  send_players(env);
}
コード例 #12
0
ファイル: graph_cmd6.c プロジェクト: christophewang/Zappy
void		cmd_sst(t_serv *serveur, t_client *client, int cs, char **tab)
{
  int		speed;

  if (tab[0] && tab[1] && !tab[2])
    {
      speed = atoi(tab[1]);
      if (speed >= 1 && speed <= 1000000)
	{
	  serveur->speed = speed;
	  memset(client[cs].buffer, 0, BUFF_SIZE);
	  sprintf(client[cs].buffer, "sgt %d\n", serveur->speed);
	  xsend(cs, client[cs].buffer, strlen(client[cs].buffer), 0);
	  return ;
	}
    }
  xsend(cs, "sbp\n", strlen("sbp\n"), 0);
}
コード例 #13
0
ファイル: socket_base.cpp プロジェクト: ninoles/zeromq2-2
int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_)
{
    //  Check whether the library haven't been shut down yet.
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }

    //  Check whether message passed to the function is valid.
    if (unlikely ((msg_->flags | ZMQ_MSG_MASK) != 0xff)) {
        errno = EFAULT;
        return -1;
    }

    //  Process pending commands, if any.
    int rc = process_commands (false, true);
    if (unlikely (rc != 0))
        return -1;

    //  At this point we impose the MORE flag on the message.
    if (flags_ & ZMQ_SNDMORE)
        msg_->flags |= ZMQ_MSG_MORE;

    //  Try to send the message.
    rc = xsend (msg_, flags_);
    if (rc == 0)
        return 0;

    //  In case of non-blocking send we'll simply propagate
    //  the error - including EAGAIN - upwards.
    if (flags_ & ZMQ_NOBLOCK)
        return -1;

    //  Oops, we couldn't send the message. Wait for the next
    //  command, process it and try to send the message again.
    while (rc != 0) {
        if (errno != EAGAIN)
            return -1;
        if (unlikely (process_commands (true, false) != 0))
            return -1;
        rc = xsend (msg_, flags_);
    }
    return 0;
}
コード例 #14
0
ファイル: sync_device.c プロジェクト: bowlofstew/vlee
static SOCKET server_connect(const char *host, unsigned short nport)
{
	struct hostent *he;
	char **ap;

#ifdef WIN32
	static int need_init = 1;
	if (need_init) {
		WSADATA wsa;
		if (WSAStartup(MAKEWORD(2, 0), &wsa))
			return INVALID_SOCKET;
		need_init = 0;
	}
#elif defined(USE_AMITCP)
	if (!socket_base) {
		socket_base = OpenLibrary("bsdsocket.library", 4);
		if (!socket_base)
			return INVALID_SOCKET;
	}
#endif

	he = gethostbyname(host);
	if (!he)
		return INVALID_SOCKET;

	for (ap = he->h_addr_list; *ap; ++ap) {
		SOCKET sock;
		struct sockaddr_in sa;

		sa.sin_family = he->h_addrtype;
		sa.sin_port = htons(nport);
		memcpy(&sa.sin_addr, *ap, he->h_length);
		memset(&sa.sin_zero, 0, sizeof(sa.sin_zero));

		sock = socket(he->h_addrtype, SOCK_STREAM, 0);
		if (sock == INVALID_SOCKET)
			continue;

		if (connect(sock, (struct sockaddr *)&sa, sizeof(sa)) >= 0) {
			char greet[128];

			if (xsend(sock, CLIENT_GREET, strlen(CLIENT_GREET), 0) ||
				xrecv(sock, greet, strlen(SERVER_GREET), 0)) {
				closesocket(sock);
				continue;
			}

			if (!strncmp(SERVER_GREET, greet, strlen(SERVER_GREET)))
				return sock;
		}

		closesocket(sock);
	}

	return INVALID_SOCKET;
}
コード例 #15
0
ファイル: send_noop.c プロジェクト: canercandan/another-ftp
int	send_noop(t_ftp *f)
{
  char	buf[200];

  if (DEBUG)
    printf("send_noop()\n");
  sprintf(buf, SD_FMT, RQ_NOOP, "", "");
  xsend(f->s, buf, (void *) strlen(buf), 0);
  return (0);
}
コード例 #16
0
ファイル: send_pwd.c プロジェクト: canercandan/another-ftp
int	send_pwd(t_cmd *c, t_snd *s)
{
  char	buf[200];

  if (DEBUG)
    printf("send_pwd()\n");
  sprintf(buf, SD_FMT, s->req, "", "");
  xsend(c->f->s, buf, (void *) strlen(buf), 0);
  return (0);
}
コード例 #17
0
ファイル: init_pwd.c プロジェクト: scalp42/my_ftp
void		init_pwd(client_ftp_t *client_ftp)
{
  char		buffer[1024];
  int		i;

  bzero(buffer, 1024);
  xsend(client_ftp->s, "PWD\n", 4, 0);
  i = xrecv(client_ftp->s, buffer, 1024, 0);
  clean_buff(buffer, i);
  client_ftp->pwd = strdup(buffer);
}
コード例 #18
0
ファイル: device.c プロジェクト: fcondolo/rocket
static int get_track_data(struct sync_device *d, struct sync_track *t)
{
	unsigned char cmd = GET_TRACK;
	uint32_t name_len;

	assert(strlen(t->name) <= UINT32_MAX);
	name_len = htonl((uint32_t)strlen(t->name));

	/* send request data */
	if (xsend(d->sock, (char *)&cmd, 1, 0) ||
	    xsend(d->sock, (char *)&name_len, sizeof(name_len), 0) ||
	    xsend(d->sock, t->name, (int)strlen(t->name), 0))
	{
		closesocket(d->sock);
		d->sock = INVALID_SOCKET;
		return -1;
	}

	return 0;
}
コード例 #19
0
ファイル: flexse.cpp プロジェクト: ArkEngine/flexse
	void*
ServiceThread(void* args)
{
	thread_data_t* ptd = (thread_data_t*)args;
	int sock = -1;
	int ret = -1;
	int netret = -1;
	socklen_t   caddr_len=0;

	ROUTN( "ServiceThread[%u] Create OK", ptd->tid);

	while( 1 )
	{
		netret = -1;
		ret = -1;
        sock = ptd->poll->fetch_socket();
		if( sock>0 ){
            sockaddr_in cltaddr;
            caddr_len = sizeof(cltaddr);
            getpeername(sock, (sockaddr*)&cltaddr, &caddr_len );
            inet_ntop(AF_INET, (void *)&cltaddr.sin_addr, ptd->cltip, sizeof(ptd->cltip));
        }
        else
        {
            ALARM( "sock:%d %m", sock );
            continue;
        }

        memset (ptd->RecvHead, 0, sizeof(ptd->RecvHead));
        netret = xrecv(sock, ptd->RecvHead, ptd->RecvBuffSize, myConfig->RTimeMS());
        if( netret <0 && errno != EAGAIN)
        {
            DEBUG( "xrecv error. sock:%d ret:%d name:%s body_len:%d to[%u] errno[%d] msg[%m]",
                    sock, netret, ptd->RecvHead->srvname,ptd->RecvHead->detail_len,
                    myConfig->RTimeMS(), errno);
            ptd->poll->free_socket(sock, 0);
            continue;
        }
        else
        {
            ret = (ptd->servapp)( ptd );
            netret = xsend(sock, ptd->SendHead, myConfig->WTimeMS());
            if(( netret<0 || ret<0 ) && errno != EAGAIN){
                DEBUG( "xsend error. sock:%d netret:%d ret:%d errno[%d] %m", sock, netret, ret, errno );
                ptd->poll->free_socket(sock, 0);
                continue;
            }
        }
        ptd->poll->free_socket(sock, 1);
    }
    return NULL;
}
コード例 #20
0
void	send_team(t_env *env)
{
  int		pos;
  char		tmp[BUF_SIZE];

  pos = 1;
  while (pos <= env->nb_team)
    {
      sprintf(tmp, "tna %s\n", env->clt[pos].name_of_team);
      xsend(env->cs_graphic, tmp, strlen(tmp), "sendteam");
      pos++;
    }
}
コード例 #21
0
int		do_connection(t_serv *serveur, t_client *client, int cs, int i)
{
  if (serveur->team[i].nb_clients - 1 >= 0)
    {
      client[cs].team = i;
      connect_to_drone(serveur, client, cs, i);
      client[cs].timelife = 1000000 *
	(client[cs].drone->nourriture * 126 / serveur->speed);
      client[cs].timelaps = 0;
      client[cs].flag = 0;
      xgettimeofday(&client[cs].life);
      delete_command(client, cs);
      memset(client[cs].buffer, 0, BUFF_SIZE);
      sprintf(client[cs].buffer, "%d\n%d %d\n",
	      --serveur->team[client[cs].team].nb_clients,
	      serveur->world_x, serveur->world_y);
      xsend(cs, client[cs].buffer, strlen(client[cs].buffer), 0);
      if (serveur->graphic_flag)
	send_pnw(serveur, client, cs);
      return (1);
    }
  xsend(cs, KO, strlen(KO), 0);
  return (-1);
}
コード例 #22
0
ファイル: deflate.c プロジェクト: oe5hpm/dxlAPRS
static void copystr(char dbuf[], uint32_t dbuf_len, int32_t * outlen,
                 struct deflate_XCONTEXT * c)
{
   uint32_t n;
   uint32_t i;
   if (c->lencode<3UL) *outlen = -2L;
   n = c->wp;
   i = (n+32768UL)-c->distcode&32767UL; /* start in ring */
   while (c->lencode>0UL) {
      xsend(c, c->ring[i], dbuf, dbuf_len, outlen); /* copy string */
      i = i+1UL&32767UL;
      if (i==n) i = (n+32768UL)-c->distcode&32767UL;
      --c->lencode;
   }
} /* end copystr() */
コード例 #23
0
void	send_player_level(t_env *env, int cs)
{
  int		pos;
  char		tmp[BUF_SIZE];

  pos = 0;
  while (pos < MAXCLIENT + 5)
    {
      if (env->clt[pos].level == env->clt[cs].level)
	{
	  sprintf(tmp, "plv %i %i\n", pos, env->clt[pos].level);
	  xsend(env->cs_graphic, tmp, strlen(tmp), "player");
	}
      pos++;
    }
}
コード例 #24
0
ファイル: main.c プロジェクト: AstoniaDev/openMerc
void say(char *input)
{
	int n;
	char buf[16];
	buf[0]=CL_CMD_INPUT1;
	for (n=0; n<15; n++)
		buf[n+1]=input[n];
	xsend(buf);

	buf[0]=CL_CMD_INPUT2;
	for (n=0; n<15; n++)
		buf[n+1]=input[n+15];
	xsend(buf);

	buf[0]=CL_CMD_INPUT3;
	for (n=0; n<15; n++)
		buf[n+1]=input[n+30];
	xsend(buf);

	buf[0]=CL_CMD_INPUT4;
	for (n=0; n<15; n++)
		buf[n+1]=input[n+45];
	xsend(buf);

	buf[0]=CL_CMD_INPUT5;
	for (n=0; n<15; n++)
		buf[n+1]=input[n+60];
	xsend(buf);

	buf[0]=CL_CMD_INPUT6;
	for (n=0; n<15; n++)
		buf[n+1]=input[n+75];
	xsend(buf);

	buf[0]=CL_CMD_INPUT7;
	for (n=0; n<15; n++)
		buf[n+1]=input[n+90];
	xsend(buf);

	buf[0]=CL_CMD_INPUT8;
	for (n=0; n<15; n++)
		buf[n+1]=input[n+105];
	xsend(buf);
}
コード例 #25
0
ファイル: rtsp.c プロジェクト: clkao/msdl
/*
 * send rtsp header (rtsp_hdr->buffer)
 */
int rtsp_send_request(struct stream_t *stream,
		      struct rtsp_header_t *rtsp_hdr)
{
    int ret;
  
    /* dbg */
    display(MSDL_DBG,"SEND rtsp header ------------>\n"
	    "%s\n--(%d bytes)---------------<\n",
	    rtsp_hdr->buffer,(int)rtsp_hdr->buffer_len);
    
    ret = xsend(stream->netsock->sock,rtsp_hdr->buffer,rtsp_hdr->buffer_len);
  
    /* OK change stream->stream_ctrl->rtsp_ctrl->cseq!! */
    stream->stream_ctrl->rtsp_ctrl->cseq++;
  
    return ret;
}
コード例 #26
0
ファイル: view.c プロジェクト: christophewang/Zappy
void		do_voir(t_serv *serveur, t_client *client, int cs)
{
  t_view	view;

  printf(LOOK, B, serveur->team[client[cs].team].name, client[cs].id_drone, D);
  memset(view.buffer, 0, BUFF_SIZE);
  strcat(view.buffer, "{");
  if (client[cs].drone->direction == NORTH)
    north_view(serveur, client, cs, &view);
  else if (client[cs].drone->direction == EAST)
    east_view(serveur, client, cs, &view);
  else if (client[cs].drone->direction == SOUTH)
    south_view(serveur, client, cs, &view);
  else if (client[cs].drone->direction == WEST)
    west_view(serveur, client, cs, &view);
  strcat(view.buffer, "}\n");
  xsend(cs, view.buffer, strlen(view.buffer), 0);
  delete_command(client, cs);
  parse_command(serveur, client, cs);
}
コード例 #27
0
ファイル: rtsp.c プロジェクト: clkao/msdl
/*
 * wrappers for each request
 */
int rtsp_200ok(struct stream_t *stream,int cseq,char *session)
{
    int ret;
    int buflen = 100 + strlen(rtsp_protocol_version) + strlen(session);
    char *buf = xmalloc(buflen + 1);
  
    snprintf(buf,buflen,
	     "%s 200 OK\r\n"
	     "Cseq: %u\r\n"
	     "Session: %s\r\n"
	     "\r\n",
	     rtsp_protocol_version,
	     cseq,
	     session);
  
    ret = xsend(stream->netsock->sock,buf,strlen(buf));
    display(MSDL_DBG,"=send 200 OK============\n%s\n=================\n",buf);
  
    free(buf);
    return ret;
}
コード例 #28
0
ファイル: graph_cmd6.c プロジェクト: christophewang/Zappy
void		cmd_pin(t_serv *serveur, t_client *client, int cs, char **tab)
{
  int		i;
  int		id;

  if (tab[0] && tab[1] && !tab[2])
    {
      i = 0;
      id = atoi(tab[1]);
      while (i < serveur->limit)
	{
	  if (serveur->fd_type[i] == FD_CLIENT &&
	      client[i].teamflag == 1 && client[i].id == id)
	    {
	      send_pin(serveur, client, i);
	      return ;
	    }
	  i++;
	}
    }
  xsend(cs, "sbp\n", strlen("sbp\n"), 0);
}
コード例 #29
0
ファイル: rep_ep.c プロジェクト: tniuli/xio
static int repep_send (struct epbase *ep, char *ubuf)
{
	int rc = -1;
	struct rrhdr *pg = get_rrhdr (ubuf);
	struct rtentry *rt = rt_cur (ubuf);
	struct tgtd *tg = 0;

	mutex_lock (&ep->lock);
	get_tgtd_if (tg, &ep->connectors, !uuid_compare (get_rep_tgtd (tg)->uuid, rt->uuid) );
	if (tg)
		list_move (&tg->item, &ep->connectors);
	mutex_unlock (&ep->lock);

	pg->go = 0;
	pg->end_ttl = pg->ttl;

	if (tg) {
		rc = xsend (tg->fd, ubuf);
		DEBUG_OFF ("ep %d send resp %10.10s to socket %d", ep->eid, ubuf, tg->fd);
	}
	return rc;
}
コード例 #30
0
ファイル: poll_ts.c プロジェクト: tniuli/xio
static void xclient (const char *pf)
{
	int sfd, i;
	int64_t nbytes;
	char buf[1024] = {};
	char *ubuf;
	char host[1024] = {};

	sprintf (host, "%s%s", pf, "://127.0.0.1:18897");
	randstr (buf, 1024);
	BUG_ON ( (sfd = xconnect (host) ) < 0);
	for (i = 0; i < cnt; i++) {
		nbytes = rand() % 1024;
		ubuf = ubuf_alloc (nbytes);
		memcpy (ubuf, buf, nbytes);
		BUG_ON (0 != xsend (sfd, ubuf) );
		BUG_ON (0 != xrecv (sfd, &ubuf) );
		DEBUG_OFF ("%d recv response", sfd);
		assert (memcmp (ubuf, buf, nbytes) == 0);
		ubuf_free (ubuf);
	}
	xclose (sfd);
}