Example #1
0
int		ia_play(t_player *player, t_map map)
{
  t_msg		msg;
  int		ret;

  lock();
  if (check_dead(player, map) == FAILURE)
    ret = FAILURE;
  else if (read_msg(CASE_DEAD_MSG_ID + player->pos.x + player->pos.y
		    * MAP_SIZE, &msg, IPC_NOWAIT) == SUCCESS)
    ret = ia_exit(player, map);
  else if (read_msg(TEAM_MSG_ID + player->id_team, &msg, IPC_NOWAIT)
	   == SUCCESS)
    {
      if (msg.type == MSG_GETOUT)
	ret = ia_exit(player, map);
      else if (msg.type == MSG_GO_TO_ALLY || msg.type == MSG_GO_TO_ENNEMY)
	ret = ia_path_finding(player, map, msg.type);
    }
  else
    {
      what_msg_send(player, map);
      ret = ia_path_finding(player, map, MSG_GO_TO_ENNEMY);
    }
  if (count_nb_ennemy(map, player, &ret) == FAILURE)
    printf("Team [%i] WON!\n", player->id_team);
  return (unlock() == SUCCESS && ret);
}
Example #2
0
    /* This function makes sure the buffer is empty and OBD is ready to work 
     * correctly by writing a neutral command and checking the expected answer. 
     * Arguments:
     *              fd: file descriptor.
     * Return value:
     *              -1: Not synced properly.
     *               0: Synced properly.
     */
    int sync_protocol(int fd) {
        char answer[MAX_ANSWER];
        int n = -1;

        // Empty input channel 
#if DEBUGLEVEL
        fprintf(stderr, "DEBUG::sync_protocol, starting to clean input\n");
#endif
        while (1) {
            int status;
            int bytes;
            while ((status = read_msg(fd, answer, MAX_ANSWER, -1)) > 0);
            if (status != OBD_EMPTY) {
                perror("error emptying buffer");
                break;
            }
#if DEBUGLEVEL
            fprintf(stderr, "DEBUG::sync_protocol, input empty\n");
#endif
            write_atmsg(fd, OBD_INITSTRING);
            sleep(1);
#if DEBUGLEVEL
            fprintf(stderr, "DEBUG::sync_protocol, sent command echo off (AT%s)\n", OBD_INITSTRING);
#endif
            bytes = read_msg(fd, answer, MAX_ANSWER, 0); //TODO por que timeout= 0 y no guardamos su salida
#if DEBUGLEVEL
            fprintf(stderr, "DEBUG::sync_protocol, read answer=%s y bytes =%d\n", answer, bytes);
#endif
            if (strncmp(answer, "OK", strlen("OK")) == 0) {
                n = 0;
                break;
            }
        }
        return n;
    }
Example #3
0
File: mon.c Project: hfs/afd
/*############################## tcp_cmd() ##############################*/
static int
tcp_cmd(char *fmt, ...)
{
   int     bytes_buffered,
           bytes_done;
   va_list ap;

   va_start(ap, fmt);
   (void)vfprintf(p_control, fmt, ap);
   va_end(ap);
   (void)fprintf(p_control, "\r\n");
   (void)fflush(p_control);

   while ((bytes_buffered = read_msg()) != INCORRECT)
   {
      if (bytes_buffered > 3)
      {
         if ((msg_str[0] == '2') && (msg_str[1] == '1') &&
             (msg_str[2] == '1') && (msg_str[3] == '-'))
         {
            bytes_buffered = read_msg();
            break;
         }
         if ((isdigit((int)msg_str[0])) && (isdigit((int)msg_str[1])) &&
             (isdigit((int)msg_str[2])) && (msg_str[3] == '-'))
         {
            return(-(((msg_str[0] - '0') * 100) + ((msg_str[1] - '0') * 10) +
                   (msg_str[2] - '0')));
         }
         if ((isupper((int)msg_str[0])) && (isupper((int)msg_str[1])) &&
             (msg_str[2] == ' '))
         {
            if (evaluate_message(&bytes_done) == AFDD_SHUTTING_DOWN)
            {
               return(-AFDD_SHUTTING_DOWN);
            }
            bytes_buffered -= bytes_done;
         }
         else
         {
            mon_log(WARN_SIGN, __FILE__, __LINE__, 0L, msg_str,
                    "Reading garbage, don't know what to do?");
            return(INCORRECT);
         }
      }
      else
      {
         mon_log(WARN_SIGN, __FILE__, __LINE__, 0L, msg_str,
                 "Reading garbage, don't know what to do?");
         return(INCORRECT);
      }
   }

   return(bytes_buffered);
}
Example #4
0
int process_msg(struct client* cli, FILE* file, int* count){

	char buff[BUFFSZ];
	int rc;
	struct msg_head m_msg;
	
	rc = read_msg(cli, buff);

	switch(cli->last_hdr.code){
	case MSG_BLOB:
		store_count(count, (int*) buff);
		cli->last_hdr.code=MSG_NULL;
		break;
	default:
		cli->last_hdr=*((struct msg_head*)buff);

		if (cli->last_hdr.code==MSG_BLOB)
			break;
	
		if (feof(file)){
			cli->last_hdr.code=TERM;
			break;
		}

		rc = fread(buff, sizeof(char), MAX_BLOBSZ, file);

		rc = send_new_blob(cli, buff, rc);
	}
}
Example #5
0
static void		client(int sock, const char *name)
{
	char	buff[BUF_SIZE + 1];
	fd_set	rdfs;

	write_server(sock, name);
	while (42)
	{
		do_select(sock, &rdfs);
		if (FD_ISSET(STDIN_FILENO, &rdfs))
		{
			read_msg(buff);
			write_server(sock, buff);
		}
		else if (FD_ISSET(sock, &rdfs))
		{
			if (read_server(sock, buff) == 0)
			{
				printf("Server disconnected !\n");
				break ;
			}
			ft_putendl(buff);
			if (ft_strcmp(buff, "Pseudo already used") == 0)
				write_server(sock, pseudo());
		}
	}
	close(sock);
}
Example #6
0
int main(int argc, char **argv) {


  if (!strcmp(argv[2], "write_g")) {
    write_g(argv[1], argv[3], argv[4], argv[5]);
  } else if (!strcmp(argv[2], "write")) {
		if (argc == 4) {
			write_msg(argv[1], argv[3]);
		} else {
			write_msg(argv[1], NULL);
		}

	} else if(!strcmp(argv[2], "read")) {
		read_msg(argv[1]);
	} else if(!strcmp(argv[2], "thread")){

		pthread_t read_t;
	  	int ret = 0;

	    ret = pthread_create(&read_t, NULL, read_canbus, NULL);
	    if (ret != 0){
	    	fprintf(stderr, "Creat pthread error!\n");
	        exit(-EINVAL);
	    }

	    pthread_join(read_t, NULL);
	} else if(!strcmp(argv[2], "wiki")){
		wiki(argc, argv);
	}

	fprintf(stderr, "Main thread finished!\n");

	return 0;
}
Example #7
0
void do_irc(int fd) {

    char recvbuf[MAX_MSG_LEN + 1];
    char recvbuf2[MAX_MSG_LEN+1];
    char sendbuf[MAX_MSG_LEN + 1];

    char tokens[MAX_MSG_TOKENS][MAX_MSG_LEN+1];
    int length;

    bzero(&recvbuf, sizeof(recvbuf));
    bzero(&sendbuf, sizeof(sendbuf));

   	read_msg(fd, recvbuf);

    bzero(&recvbuf2, sizeof(recvbuf2));

    trim(recvbuf, recvbuf2);

   	length = tokenize(recvbuf2, tokens);

   	parse_msg(tokens, length, sendbuf, fd);



}
bool mutex_trig_handle::timed_wait(int tm)
{
	assert(!_outActor);
	if (!read_msg())
	{
		bool timed = false;
		LAMBDA_REF2(ref2, _hostActor, timed);
		if (tm >= 0)
		{
			_hostActor->delay_trig(tm, [&ref2]
			{
				ref2.timed = true;
				ref2._hostActor->pull_yield();
			});
		}
		_hostActor->push_yield();
		if (!timed)
		{
			if (tm >= 0)
			{
				_hostActor->cancel_delay_trig();
			}
			return true;
		}
		_waiting = false;
		return false;
	}
	return true;
}
Example #9
0
// 2nd REQ socket monitor thread
static void req2_socket_monitor (void *ctx)
{
    zmq_event_t event;
    std::string ep ;
    int rc;

    void *s = zmq_socket (ctx, ZMQ_PAIR);
    assert (s);

    rc = zmq_connect (s, "inproc://monitor.req2");
    assert (rc == 0);
    while (!read_msg(s, event, ep)) {
        assert (ep == addr);
        switch (event.event) {
            case ZMQ_EVENT_CONNECTED:
                assert (event.value > 0);
                req2_socket_events |= ZMQ_EVENT_CONNECTED;
                break;
            case ZMQ_EVENT_CLOSED:
                assert (event.value != 0);
                req2_socket_events |= ZMQ_EVENT_CLOSED;
                break;
        }
    }
    zmq_close (s);
}
Example #10
0
/*++++++++++++++++++++++++++++++ get_reply() ++++++++++++++++++++++++++++*/
static int
get_reply(void)
{
   int ret;

   for (;;)
   {
      if (read_msg() == INCORRECT)
      {
         return(INCORRECT);
      }

      if ((msg_str[0] == '+') &&
          ((msg_str[1] == 'O') || (msg_str[1] == 'o')) &&
          ((msg_str[2] == 'K') || (msg_str[2] == 'k')))
      {
         ret = POP3_OK;
         break;
      }
      else if ((msg_str[0] == '-') &&
               ((msg_str[1] == 'E') || (msg_str[1] == 'e')) &&
               ((msg_str[2] == 'R') || (msg_str[2] == 'r')) &&
               ((msg_str[3] == 'R') || (msg_str[3] == 'r')))
           {
              ret = POP3_ERROR;
              break;
           }
   }

   return(ret);
}
Example #11
0
/**
 * If we can terminate, return true. If all schedulers are waiting, one of
 * them will stop the ASIO back end and tell the cycle detector to try to
 * terminate.
 */
static bool quiescent(scheduler_t* sched, uint64_t tsc, uint64_t tsc2)
{
  read_msg(sched);

  if(sched->terminate)
    return true;

  if(sched->ack_count == scheduler_count)
  {
    if(sched->asio_stopped)
    {
      for(uint32_t i = 0; i < scheduler_count; i++)
        send_msg(i, SCHED_TERMINATE, 0);

      sched->ack_token++;
      sched->ack_count = 0;
    } else if(ponyint_asio_stop()) {
      sched->asio_stopped = true;
      sched->ack_token++;
      sched->ack_count = 0;

      // Run another CNF/ACK cycle.
      for(uint32_t i = 0; i < scheduler_count; i++)
        send_msg(i, SCHED_CNF, sched->ack_token);
    }
  }

  ponyint_cpu_core_pause(tsc, tsc2, use_yield);
  return false;
}
Example #12
0
HOT_INLINE
static void cb_Send(
    hot_contextID_t id, 
    unsigned *cs
) {
    hot_err_t err;
    hot_endpt_t endpt ;
    hot_uint32 origin ;
    hot_msg_t msg;
    hot_context_t s;
    void *env;
    hot_ens_ReceiveSend_cback receive_send;

    trace("cb_Send");
    read_int(&origin);
    read_msg(&msg);
    
    begin_critical(); {
	s = lookup_context(id);
	env = s->env;
	assert(origin < s->nmembers) ;
	endpt = s->view[origin] ;
	receive_send = s->conf.receive_send;
    } end_critical();

    if (receive_send != NULL) {
      trace("receive_send");
	(*receive_send)(s, env, &endpt, msg);
    }

    err = hot_msg_Release(&msg);
    if (err != HOT_OK)
	hot_sys_Panic(hot_err_ErrString(err));
}
Example #13
0
void Client::wait_for_start() {
  for (;;) {
    std::string response = read_msg();
    const std::vector<std::string> tokens = tokenize_msg(response);

    if (tokens.size() == 4 && tokens[0] == "BEGIN" &&
        tokens[1] == "CHINESECHECKERS") {
      // Found BEGIN GAME message, determine if we play first
      if (tokens[2] == name) {
        // We go first!
        opp_name = tokens[3];
        my_player = player1;
        break;
      } else if (tokens[3] == name) {
        // They go first
        opp_name = tokens[2];
        my_player = player2;
        break;
      } else {
        std::cerr << "Did not find '" << name
                  << "', my name, in the BEGIN command.\n"
                  << "# Found '" << tokens[2] << "' and '" << tokens[3] << "'"
                  << " as player names. Received message '" << response << "'"
                  << std::endl;
        std::cout << "#quit" << std::endl;
        std::exit(EXIT_FAILURE);
      }
    } else if (response == "DUMPSTATE") {
      // std::cout << gs.dumpState() << std::endl;
    } else if (tokens[0] == "LOADSTATE") {
      std::string new_state = response.substr(10);
      /*
      if (!gs.loadState(new_state))
        std::cerr << "Failed to load '" << new_state << "'\n";
      */
    } else if (response == "LISTMOVES") {
      /*
      std::vector<Move> moves;
      gs.getMoves(moves);
      for (const auto i : moves)
        std::cout << i.from << ", " << i.to << "; ";
      std::cout << std::endl;
      */
    } else if (tokens[0] == "MOVE") {
      // Just apply the move
      // const Move m = gs.translate_to_local(tokens);
      // gs.apply_move(m);
    } else {
      std::cerr << "Unexpected message " << response << "\n";
    }
  }

  // Game is about to begin, restore to start state in case DUMPSTATE/LOADSTATE/LISTMOVES
  // were used
  //gs.reset();

  // Player 1 goes first
  current_player = player1;
}
Example #14
0
void broker::scribe::consume(const void*, size_t num_bytes) {
  CAF_LOG_TRACE(CAF_ARG(num_bytes));
  if (m_disconnected) {
    // we are already disconnected from the broker while the multiplexer
    // did not yet remove the socket, this can happen if an IO event causes
    // the broker to call close_all() while the pollset contained
    // further activities for the broker
    return;
  }
  auto& buf = rd_buf();
  buf.resize(num_bytes);                       // make sure size is correct
  read_msg().buf.swap(buf);                    // swap into message
  m_broker->invoke_message(invalid_actor_addr, // call client
                           invalid_message_id, m_read_msg);
  read_msg().buf.swap(buf); // swap buffer back to stream
  flush();                  // implicit flush of wr_buf()
}
Example #15
0
int ldcs_audit_server_md_recv_from_parent(ldcs_message_t *msg)
{
   int fd;
   node_peer_t peer;

   cobo_get_parent_socket(&fd);
   return read_msg(fd, &peer, msg);
}
Example #16
0
// Sends a msg to stdout and verifies that the next message to come in is it
// echoed back. This is how the server validates moves
void Client::print_and_recv_echo(const std::string &msg) const {
  // Note the endl flushes the stream, which is necessary
  std::cout << msg << std::endl;
  const std::string echo_recv = read_msg();
  if (msg != echo_recv)
    std::cerr << "Expected echo of '" << msg << "'. Received '" << echo_recv
              << "'" << std::endl;
}
Example #17
0
void Display::newConnection()
{
    qDebug() << "Woot woot actually connected";
    qDebug() << "lol jk m8 nothing works at all";
    QTcpSocket *socket = server->nextPendingConnection();
    qDebug() << socket->peerAddress();
    connect(socket, SIGNAL(readyRead()),
    this, SLOT(read_msg()));
}
Example #18
0
int application_request(int fd,data_person * users,int * newid)
{
    binary_semaphore_wait(semaphore);
    person person;
    simple_person * simple_person;
    int ans=0;
    clsvbuff buff;

    if(read_msg(fd,&buff)<0)
      return -1;

    switch(buff.opc)
    {
      case GET_INFO:
          ans = get_info(&buff,users,newid,&person);
          ans_get_info(fd,&buff,ans,&person);
          break;
      case GET_MATCHS:
          ans = get_matchs(&buff,users,&simple_person);
          ans_get_matchs(fd,ans,&buff,&simple_person);
          break;
      case SHOW_PEOPLE:
          ans = show_people(&buff,users,newid,&simple_person);
          ans_show_people(fd,ans,&buff,&simple_person);
          break;
      case REGISTER:
          ans=register_user(&buff,users,newid);
          ans_register_user(fd,ans,&buff);
          break;
      case LOGIN: /*In this case ans doubles as opOK*/
          ans = login(&buff,users,newid);
          ans_login(fd,ans,&buff);
          break;
      case EVALUATION:  /*In this case ans doubles as opOK*/
          users[buff.id_client-1].last_evaluation=buff.data.clsv_evaluation.id;
          if(buff.data.clsv_evaluation.like==true)
          {
            ans = evaluation(&buff,users);
            ans_evaluation(fd,ans,&buff);
          }
          else
           ans_evaluation(fd,0,&buff);

          break;
      default: /*OPC NOT RECOGNIZED*/
          return -1;
        break;
    }

    binary_semaphore_post(semaphore);



    return 0;

}
int main (void)
{
	char msg[MSG_LENG];
	
	printf("Enter a message: ");
	read_msg (msg, MSG_LENG);
	result (analyze (msg));
	
	return 0;
}
Example #20
0
// Sends msg to stdout. Verifies it is echoed back. This is how the server
// validates moves.
void print_and_recv_echo(const char *msg) {
    fprintf(stdout, "%s\n", msg);
    fflush(stdout);

    read_msg();
    if (strcmp(msg, message) != 0) {
        fprintf(stderr, "Expected echo of '%s'. Received '%s'\n", msg, message);
        fflush(stderr);
    }
}
int main (void)
{
	char msg[MSG_LENG];
	
	printf("Enter a message: ");
	read_msg (msg, MSG_LENG);
	result (is_palindrome (msg));
	
	return 0;
}
Example #22
0
ssize_t forward_msg_read(int from_fd, int to_fd, uint8_t **buff) {
  ssize_t read_len;

  if ((read_len = read_msg(from_fd, buff)) < 0)
    return -1;

  if (write_msg(to_fd, *buff, read_len) < 0)
    return -1;

  return read_len;
}
Example #23
0
void
print_message (int msgid, ...)
{
    va_list argptr;                     /*  Argument list pointer            */

    read_msg (msgid);                   /*  Retrieve message into msgline    */
    va_start (argptr, msgid);           /*  Start variable arguments list    */
    vfprintf (stderr, msgline, argptr);
    va_end   (argptr);                  /*  End variable arguments list      */
    fprintf  (stderr, "\n");
    fflush   (stderr);
}
void mutex_trig_handle::wait()
{
	if (!read_msg())
	{
		if (!_outActor)
		{
			_hostActor->push_yield();
		} 
		else
		{
			_hostActor->push_yield_as_mutex();
		}
	}
}
Example #25
0
int wait_connection(int channel_fd) {
  ssize_t msg_size;
  u_int8_t * buff;

  /* Wait a connection from the client */
  if (((msg_size = read_msg(channel_fd,&buff)) < 0) ||
      (msg_size != strlen(CONNECTION_STRING) ||
      strncasecmp((const char *)CONNECTION_STRING,(const char *)buff,msg_size))) {
    /* Protocol error */
    return (-1);
  }

  return (0);
}
Example #26
0
File: port.c Project: migadu/gmimex
int main(void) {
    int bytes_read;
    gchar buffer[MAX_BUFFER_SIZE];
    JSON_Value *root_value;
    JSON_Object *root_object;
    gchar *json_str;
    gchar *func_name;
    gchar *path;

    while((bytes_read = read_msg(buffer)) > 0) {
    	json_str = g_strndup((const gchar *)buffer, bytes_read);
    	root_value = json_parse_string(json_str);
    	root_object = json_value_get_object(root_value);
    	func_name = (gchar *)json_object_get_string(root_object, "exec");
    	path = (gchar *)json_object_get_string(root_object, "path");
			GString *json_message = NULL;

    	if (!g_ascii_strcasecmp(func_name, "get_preview_json")) {
				json_message = gmimex_get_json(path, JSON_NO_MESSAGE_CONTENT);
  			if (!json_message) {
  				send_err();
  			} else {
					send_msg((gchar *)json_message->str, json_message->len);
			  	g_string_free(json_message, TRUE);
			  }
    	} else if (!g_ascii_strcasecmp(func_name, "get_json")) {
  			gboolean raw = json_object_get_boolean(root_object, "raw");
  			json_message = gmimex_get_json(path, (raw ? JSON_RAW_MESSAGE_CONTENT : JSON_PREPARED_MESSAGE_CONTENT));
  			if (!json_message) {
  				send_err();
  			} else {
					send_msg((gchar *)json_message->str, json_message->len);
			  	g_string_free(json_message, TRUE);
			  }
    	} else if (!g_ascii_strcasecmp(func_name, "get_part")) {
    		int part_id = json_object_get_number(root_object, "partId");
			  GByteArray *part_content = gmimex_get_part(path, part_id);
			  if (!part_content) {
			  	send_err();
			  } else {
    			send_msg((gchar *)part_content->data, part_content->len);
    			g_byte_array_free(part_content, TRUE);
    		}
    	}
    	json_value_free(root_value);
    	g_free(json_str);
    }
    return 0;
}
Example #27
0
static void *imu_reader (void *args)
{
	DDS_DynamicDataReader	dr;
	DDS_WaitSet		ws;
	DDS_SampleStateMask	ss = DDS_NOT_READ_SAMPLE_STATE;
	DDS_ViewStateMask	vs = DDS_ANY_VIEW_STATE;
	DDS_InstanceStateMask	is = DDS_ANY_INSTANCE_STATE;
	DDS_ReadCondition	rc;
	DDS_ConditionSeq	conds = DDS_SEQ_INITIALIZER (DDS_Condition);
	DDS_Duration_t		to;
	DDS_ReturnCode_t	ret;

	dr = args;

	ws = DDS_WaitSet__alloc ();
	if (!ws)
		fatal ("Unable to allocate a WaitSet!");

	if (verbose)
		printf ("DDS Waitset allocated.\r\n");

	rc = DDS_DataReader_create_readcondition (dr, ss, vs, is);
	if (!rc)
		fatal ("DDS_DataReader_create_readcondition () returned an error!");

	if (verbose)
		printf ("DDS Readcondition created.\r\n");

	ret = DDS_WaitSet_attach_condition (ws, rc);
	if (ret)
		fatal ("Unable to attach condition to a WaitSet!");

	while (!aborting) {
		to.sec = 0;
		to.nanosec = 200000000;	/* Timeout after 200ms. */
		ret = DDS_WaitSet_wait (ws, &conds, &to);
		if (ret == DDS_RETCODE_TIMEOUT)
			continue;

		read_msg (NULL, dr);
	}
	ret = DDS_WaitSet_detach_condition (ws, rc);
	if (ret)
		fatal ("Unable to detach condition from WaitSet (%s)!", DDS_error (ret));

	DDS_WaitSet__free (ws);

	return (NULL);
}
Example #28
0
    /* 
     * Reads input from OBD when VIN is asked, removing it from the string and 
     * adding a zero at the end. This function goes byte by byte cleaning the 
     * output information for a better output. 
     * Arguments: 
     *              fd: Open file descriptor to read from.
     *              vinstring: pointer of the string in which to store the information.
     *              l: maximum length of the buffer.
     *              timeout : 
     *                          > 0 time to wait for input before aborting read.
     *                          0 > wait input forever.
     *                          -1  uses non blocking input and returns inmediately 
     *                              if input stream is empty in this moment.
     * The out parameter is an integer showing the error or the length of what is
     * being read.
     * Return value:
     *          bytes: read n characters not including EOL nor final zero
     *          OBD_EMPTY: non block input returned inmediately when using non 
     *                     blocking input.
     *          OBD_CLOSED: fd is closed.
     *          OBD_TIMEOUT: blocking input didn't answer before specified timeout.
     *          OBD_ERROR: other errors.
     */
    int read_VINmsg(int fd, char *vinstring, int l, int timeout) {
        int i, r, bytes = 0;
        char buffer[OBDV_MAXSTR];

        for (i = 0; i <= 3; i++) {
            r = read_msg(fd, buffer, l, timeout);
            if (r <= 0)
                return r;
            bytes = r + bytes;
            if (i != 0)
                strcat(vinstring, buffer);
            sleep(2);
        }
        return bytes;
    }
Example #29
0
static int map_new_blktapctrl(blkif_t *blkif)
{
    DPRINTF("Received a poll for a new devmap\n");
    if (write_msg(blkif->fds[WRITE], CTLMSG_NEWDEV, blkif, NULL) <= 0) {
        DPRINTF("Write_msg failed - CTLMSG_NEWDEV\n");
        return -EINVAL;
    }

    if (read_msg(blkif->fds[READ], CTLMSG_NEWDEV_RSP, blkif) <= 0) {
        DPRINTF("Read_msg failed - CTLMSG_NEWDEV_RSP\n");
        return -EINVAL;
    }
    DPRINTF("Exiting map_new_blktapctrl\n");

    return blkif->minor - 1;
}
Example #30
0
// Reads a line from the server and tokenizes the result based on a space
// delimiter
void read_msg_and_tokenize(void) {
    read_msg();

    // Copy message to tokens[0] to not destroy it with strtok
    char buffer[MAX_LINE_LEN];
    strcpy(buffer, message);

    // Tokenize based on space
    char *token = strtok(buffer, " ");
    tokens_size = 0;
    while (token != NULL && tokens_size < MAX_TOKENS) {
        strcpy(tokens[tokens_size], token);
        tokens_size++;
        token = strtok(NULL, " ");
    }
}