Beispiel #1
0
VALUE mc_flush_all(int argc, VALUE *argv, VALUE self) {
  memcached_st *mc;
  VALUE delay;
  static memcached_return_t result;

  Data_Get_Struct(self, memcached_st, mc);
  rb_scan_args(argc, argv, "01", &delay);

  result = memcached_flush(mc, RTEST(delay) ? NUM2UINT(delay) : 0);

  if (result == MEMCACHED_SUCCESS) {
    return Qnil;
  } else {
    return throw_error(&result);
  }
}
 bool done() {
    //rankprintf("last_snt = %d\n", last_sent);
    if (-1 == last_sent) return true;
    //task_list[last_sent].display();
    if (true != task_list[last_sent].sent) throw_error("Task never sent");
    if (true == task_list[last_sent].complete) return true;
    else {
       int data = get_status(this_comm);
       rankprintf("Rec'd status %d from node 1\n", data);
       if (STATUS_IDLE == data) {
          task_list[last_sent].complete = true;
          return true;
       }
       else return false;
    }
 }
Beispiel #3
0
static pSlipObject lookup_variable_value(pSlip gd, pSlipObject var, pSlipEnvironment env)
{
	pSlipValue v;

	do
	{
		v = ScanForVar(var, env);
		if (v != NULL)
			return v->val;

		env = enclosing_environment(env);
	}while (env != NULL);

	throw_error(gd, "unbound variable %s for lookup\n", (char*)var->data.symbol.value);
	return NULL;
}
Beispiel #4
0
void save(struct lexeme *tmpData, char to_save) {
  char *holder = NULL;

  if(length>=chunks*CHUNK) { //pokud je delka retezce vetsi nez alokovane
    if(chunks)
      holder = tmpData->value.string; //napln temp
    if((tmpData->value.string = (char *)malloc(++chunks*CHUNK)) == NULL) //alokuj pamet
      throw_error(CODE_ERROR_INTERNAL, "malloc error");
    if(holder) {
      memcpy((void *)tmpData->value.string, (void *)holder, length); //kopiruj hodnotu retezce
      free(holder); //uvolni tmp
    }
  }

  tmpData->value.string[length++] = to_save; //ulozeni retezce
}
Beispiel #5
0
void push(unsigned int **last_multis, unsigned int multiplier) {
  unsigned int *tmp = realloc(*last_multis, n_indents * sizeof(unsigned int));

  if (tmp == NULL) {
    throw_error(stderr, errors[14], __FILE__, __func__, __LINE__);
    flags |= EXIT;

    if (*last_multis != NULL) {
      free(*last_multis);
      *last_multis = NULL;
    }
  } else {
    *last_multis = tmp;
    (*last_multis)[n_indents - 1] = multiplier;
  }
}
Beispiel #6
0
char		*get_label_value(char **line, char *label, char *tmp)
{
	int	label_size;
	int	i;

	label_size = ft_strlen(label);
	*line = ft_strsub(*line, label_size, ft_strlen(*line) - label_size);
	free(tmp);
	i = 0;
	while (i < label_size - 1)
	{
		if (ft_strchr(LABEL_CHARS, label[i]) == NULL)
			throw_error(1);
		i++;
	}
	return (label);
}
cata::optional<int> cata::string_formatter::read_number_or_argument_index()
{
    if( consume_next_input_if( '*' ) ) {
        if( !has_digit() ) {
            return current_argument_index++;
        }
        const int index = parse_integer() - 1; // format specifiers are 1-based
        if( !consume_next_input_if( '$' ) ) {
            throw_error( "expected '$' after field precision" );
        }
        return index ;
    }
    while( has_digit() ) {
        current_format.push_back( consume_next_input() );
    }
    return cata::nullopt;
}
Beispiel #8
0
    explicit protocol_entry(int protocol)
    {
        char name_buf_[name_buffer_length];
        entry_type result_buf_, *result_;
    
        int retval = getprotobynumber_r(
            protocol,
            &result_buf_,
            name_buf_,
            sizeof name_buf_,
            &result_
        );
       
        if (result_ == nullptr || retval != 0)
            throw_error(retval);

        store_entry_elem(result_buf_);
    }
Beispiel #9
0
static void set_variable_value(pSlip gd, pSlipObject var, pSlipObject val, pSlipEnvironment env)
{
	pSlipValue v;

	do
	{
		v = ScanForVar(var, env);
		if (v != NULL)
		{
			v->val = val;
			return;
		}

		env = enclosing_environment(env);
	}while (env != NULL);

	throw_error(gd, "unbound variable %s for assignment\n", (char*)var->data.symbol.value);
}
 int send_next() {
    int q=0;
    while(true == task_list[q].sent && q < n_tasks) { 
       q++;
    }
    if (500 == q) {
       throw_error("No task");
       return -1;
    }
    debugMark(1);
    send_task(this_comm, task_list[q].task_msg[0],
                         task_list[q].task_msg[1],
                         task_list[q].task_msg[2]);
    debugMark(2);
    task_list[q].sent = true;
    last_sent = q;
    return q; 
 }
Beispiel #11
0
    explicit protocol_entry(std::string const& proto_name)
    {
        char name_buf_[name_buffer_length];
        entry_type result_buf_, *result_;

        int retval = getprotobyname_r(
            proto_name.c_str(),
            &result_buf_,
            name_buf_,
            sizeof name_buf_,
            &result_
        );
       
        if (result_ == nullptr || retval != 0)
            throw_error(retval);
        
        store_entry_elem(result_buf_);
    }
Beispiel #12
0
VALUE mc_delete(VALUE self, VALUE key) {
  memcached_st *mc;
  static memcached_return_t result;

  Data_Get_Struct(self, memcached_st, mc);

  key = StringValue(key);
  if (!use_binary(mc)) key = escape_key(key, NULL);
  result = memcached_delete(mc, RSTRING_PTR(key), RSTRING_LEN(key), 0);

  if (result == MEMCACHED_SUCCESS) {
    return Qtrue;
  } else if(result == MEMCACHED_NOTFOUND) {
    return Qnil;
  } else {
    return throw_error(&result);
  }
}
Beispiel #13
0
void load_map_file(const char *mapfile, roomBase *roomdb)
{
    FILE *fp = NULL;
    if ( (fp = fopen(mapfile, "r")) == NULL )
        throw_error("could not open mapfile");

    char line_buffer[LINE_BUFFER_SIZE] = { 0 };
    char id_buffer[LINE_BUFFER_SIZE] = { 0 };
    int coordinates_buffer[2];
    char object_ids_buffer[LINE_BUFFER_SIZE] = { 0 };
    char enemy_ids_buffer[LINE_BUFFER_SIZE] = { 0 };
    //char dependency_object_ids_buffer[LINE_BUFFER_SIZE] = { 0 };
    int locked_buffer;

    int room_index = 0;

    while ( fgets(line_buffer, LINE_BUFFER_SIZE, fp) != NULL ) {
        //sscanf(line_buffer, "%50[^|]|%d,%d|%50[^|]|%50[^|]", id_buffer, &coordinates_buffer[0], &coordinates_buffer[1], object_ids_buffer, dependency_object_ids_buffer);
        sscanf(line_buffer, "%50[^|]|%d,%d|%50[^|]|%50[^|]|%d", id_buffer, &coordinates_buffer[0], &coordinates_buffer[1], object_ids_buffer, enemy_ids_buffer, &locked_buffer);
        tokenise_room_objects(object_ids_buffer, &(roomdb->rooms[room_index]));
        tokenise_room_enemies(enemy_ids_buffer, &(roomdb->rooms[room_index]));
        //tokenise_room_dependency_objects(dependency_object_ids_buffer, &(roomdb->rooms[room_index]));
        strncpy(roomdb->rooms[room_index].id, id_buffer, ID_LENGTH);
        roomdb->rooms[room_index].coordinates[0] = coordinates_buffer[0];
        roomdb->rooms[room_index].coordinates[1] = coordinates_buffer[1];
        roomdb->rooms[room_index].locked = locked_buffer;

        //printf("ID: %s\n", id_buffer);
        //printf("Coordinates: %d,%d\n", coordinates_buffer[0], coordinates_buffer[1]);
        //printf("Room objects: %s\n", object_ids_buffer);
        //printf("Room dependency objects: %s\n", dependency_object_ids_buffer);


        memset(line_buffer, LINE_BUFFER_SIZE, '\0');
        memset(id_buffer, LINE_BUFFER_SIZE, '\0');
        memset(object_ids_buffer, LINE_BUFFER_SIZE, '\0');
        coordinates_buffer[0] = 0;
        coordinates_buffer[1] = 0;
        locked_buffer = 0;

        room_index++;
    }
    roomdb->nrooms = room_index;
}
static gboolean
daemon_find_user_by_name (AccountsAccounts      *accounts,
                          GDBusMethodInvocation *context,
                          const gchar           *name)
{
        Daemon *daemon = (Daemon*)accounts;
        User *user;

        user = daemon_local_find_user_by_name (daemon, name);

        if (user) {
                accounts_accounts_complete_find_user_by_name (NULL, context, user_get_object_path (user));
        }
        else {
                throw_error (context, ERROR_FAILED, "Failed to look up user with name %s.", name);
        }

        return TRUE;
}
static gboolean
daemon_find_user_by_id (AccountsAccounts      *accounts,
                        GDBusMethodInvocation *context,
                        gint64                 uid)
{
        Daemon *daemon = (Daemon*)accounts;
        User *user;

        user = daemon_local_find_user_by_id (daemon, uid);

        if (user) {
                accounts_accounts_complete_find_user_by_id (NULL, context, user_get_object_path (user));
        }
        else {
                throw_error (context, ERROR_FAILED, "Failed to look up user with uid %d.", (int)uid);
        }

        return TRUE;
}
Beispiel #16
0
void load_objects_file(const char *objectsfile, objectBase *objectdb)
{
    FILE *fp = NULL;
    if ( (fp = fopen(objectsfile, "r")) == NULL )
        throw_error("could not open objectsfile");

    char line_buffer[LINE_BUFFER_SIZE] = { 0 };
    char id_buffer[LINE_BUFFER_SIZE] = { 0 };
    char name_buffer[LINE_BUFFER_SIZE] = { 0 };
    char description_buffer[LINE_BUFFER_SIZE] = { 0 };
    char action_buffer[LINE_BUFFER_SIZE] = { 0 };
    char action_parameter_buffer[LINE_BUFFER_SIZE] = { 0 };
    int removeable_buffer = 0;
    int hitpoints_buffer = 0;

    int object_index = 0;

    while ( fgets(line_buffer, LINE_BUFFER_SIZE, fp) != NULL ) {
        sscanf(line_buffer, "%50[^|]|%50[^|]|%50[^|]|%d|%d|%50[^|]|%50[^|\n]", id_buffer, name_buffer, description_buffer, &removeable_buffer, &hitpoints_buffer, action_buffer, action_parameter_buffer);
        //description_buffer[strlen(description_buffer) - 1] = 0; /* Remove newline */
        strncpy(objectdb->objects[object_index].id, id_buffer, ID_LENGTH);
        strncpy(objectdb->objects[object_index].name, name_buffer, NAME_LENGTH);
        strncpy(objectdb->objects[object_index].description, description_buffer, DESCRIPTION_LENGTH);
        strncpy(objectdb->objects[object_index].action, action_buffer, ID_LENGTH);
        strncpy(objectdb->objects[object_index].action_parameter, action_parameter_buffer, ID_LENGTH);
        objectdb->objects[object_index].removeable = removeable_buffer;
        objectdb->objects[object_index].hitpoints = hitpoints_buffer;

        memset(line_buffer, '\0', LINE_BUFFER_SIZE);
        memset(id_buffer, '\0', LINE_BUFFER_SIZE);
        memset(name_buffer, '\0', LINE_BUFFER_SIZE);
        memset(description_buffer, '\0', LINE_BUFFER_SIZE);
        memset(action_buffer, '\0', LINE_BUFFER_SIZE);
        memset(action_parameter_buffer, '\0', LINE_BUFFER_SIZE);
        hitpoints_buffer = 0;
        removeable_buffer = 0;

        object_index++;
    }
    objectdb->nobjects = object_index;
    fclose(fp);
}
Beispiel #17
0
void server_node::start()
{
    if (is_started())
        throw std::runtime_error("Server node \"" + m_path + "\" is already started");

    if (m_fork) {
        m_kill_sent = false;
        m_pid = fork();
        if (m_pid == -1) {
            m_pid = 0;
            int err = -errno;
            throw_error(err, "Failed to fork process");
        } else if (m_pid == 0) {
            char buffer[3][1024] = {
                " ",
                "-c"
            };
            std::string ios_path = ioserv_path();
            char * const args[] = {
                const_cast<char*>(ios_path.c_str()),
                buffer[1],
                const_cast<char*>(m_path.c_str()),
                NULL
            };
            auto ld_path = std::string("LD_LIBRARY_PATH=") + getenv("LD_LIBRARY_PATH");
            char * const env[] = {
                const_cast<char*>(ld_path.c_str()),
                NULL
            };
            if (execve(ios_path.data(), args, env) == -1) {
                int err = -errno;
                std::cerr << create_error(err, "Failed to start process \"%s\"", ios_path.c_str()).message() << std::endl;
                quick_exit(1);
            }
        }
    } else {
        m_node = dnet_parse_config(m_path.c_str(), 0);
    }

    if (!is_started())
        throw std::runtime_error("Can not start server with config file: \"" + m_path + "\"");
}
Beispiel #18
0
VALUE mc_prepend(VALUE self, VALUE key, VALUE value) {
  memcached_st *mc;
  static memcached_return_t result;

  Data_Get_Struct(self, memcached_st, mc);

  key = StringValue(key);
  if (!use_binary(mc)) key = escape_key(key, NULL);
  value = StringValue(value);

  result = memcached_prepend(mc, RSTRING_PTR(key), RSTRING_LEN(key), RSTRING_PTR(value), RSTRING_LEN(value), 0, 0);

  if (result == MEMCACHED_SUCCESS) {
    return Qtrue;
  } else if(result == MEMCACHED_NOTSTORED) {
    return Qfalse;
  } else {
    return throw_error(&result);
  }
}
Beispiel #19
0
int process_translate_general(Stack s, int n, PROCESSOR_RESULT result) {
	double x0, y0;
	StackItem *cur;
	if (stack_size(s) < 2 * (n + 1)) {
		return throw_error("Impossivel realizar operação. Motivo: há menos elementos na pilha do que o necessário (stack underflow).\n", result);
	}

	y0 = stack_pop(s);
	x0 = stack_pop(s);
	
	cur = s->next;
	for (int i = 0; i < n; i++) {
		cur->value += y0;
		cur->next->value += x0;

		cur = cur->next->next;
	}

	return PROCESSOR_SUCCESS;
}
Beispiel #20
0
bool server_node::is_stopped() const
{
    if (!m_fork)
        return !m_node;

    if (m_pid) {
        int result;
        int err = waitpid(m_pid, &result, WNOHANG);
        if (err == 0) {
            return false;
        } else if (err == -1) {
            err = -errno;
            throw_error(err, "Failed to check status of pid: %d", int(m_pid));
        }

        m_pid = 0;
    }

    return true;
}
Beispiel #21
0
void Simulator::xCAST()
{
    GET_P1; GET_P2_IMM; GET_P3;
    if (p3->m_type == (ValueType)p2)
    {
        *p1 = *p3;
        return;
    }

    switch ((ValueType)p2)
    {
    case INTEGER:
        *p1 = p3->cast_int();
        break;

    case REAL:
        *p1 = p3->cast_real();
        break;

    case STRING:
        *p1 = p3->cast_string();
        break;

    case BUFFER:
        *p1 = p3->cast_buffer();
        break;

    case ARRAY:
        *p1 = p3->cast_array();
        break;

    case MAPPING:
        *p1 = p3->cast_map();
        break;

    default:
        throw_error("Failed to do cast %s to %s.\n",
                    Value::type_to_name(p3->m_type),
                    Value::type_to_name((ValueType)p2));
    }
}
Beispiel #22
0
static int	get_code_value(char *op_name, char **line, char *tmp, int nb_spaces)
{
	int	i;
	int	code;

	i = 0;
	code = 0;
	while (g_op_tab[i].cmd)
	{
		if (ft_strcmp(g_op_tab[i].cmd, op_name) == 0)
			code = g_op_tab[i].op_code;
		i++;
	}
	if (code == 0 && !is_comment_or_empty(op_name))
		throw_error(1);
	*line = ft_strsub(tmp, ft_strlen(op_name) + nb_spaces
			, ft_strlen(tmp) - ft_strlen(op_name) - nb_spaces);
	free(tmp);
	free(op_name);
	return (code);
}
Beispiel #23
0
/* Read a packet worth of data into the last packet buffer. */
static void read_one_packet(MVMThreadContext *tc, MVMIOSyncSocketData *data) {
    unsigned int interval_id = MVM_telemetry_interval_start(tc, "syncsocket.read_one_packet");
    int r;
    data->last_packet = MVM_malloc(PACKET_SIZE);
    do {
        MVM_gc_mark_thread_blocked(tc);
        r = recv(data->handle, data->last_packet, PACKET_SIZE, 0);
        MVM_gc_mark_thread_unblocked(tc);
    } while(r == -1 && errno == EINTR);
    MVM_telemetry_interval_stop(tc, interval_id, "syncsocket.read_one_packet");
    if (MVM_IS_SOCKET_ERROR(r) || r == 0) {
        MVM_free(data->last_packet);
        data->last_packet = NULL;
        if (r != 0)
            throw_error(tc, r, "receive data from socket");
    }
    else {
        data->last_packet_start = 0;
        data->last_packet_end = r;
    }
}
Beispiel #24
0
int get_config_from_file(api_config *api_data)
{
	FILE *api_data_fp;
	// int rand_state;
	time_t t;

	srand((unsigned) time(&t));
	// rand_state = rand();

	api_data_fp = fopen(API_DATA_FILE, "r");

	// file doesn't exist we need to get the pin
	throw_error(NULL == api_data_fp, CONFIG_FILE_DOESNOT_EXIST, "file " API_DATA_FILE " doesn't exist");

	log_info("file " API_DATA_FILE " exists. Let's read it");
	fread(api_data, sizeof(api_config), 1, api_data_fp);
	fclose(api_data_fp);
	return 1;
error:
	return 0;
}
Beispiel #25
0
void parse_args(int argc, char **argv, char *dpathbuf)
{
	debug = 0;
	
	int i;
	for(i=0; i<argc; i++) {
		if( COMP_STR(argv[i], "--debug" ) ) {
			printf("Enabling debug mode\n");
			debug = 1;
		}
		else if( COMP_STR(argv[i], "--data-path" ) ) {
			if( argc > (i+1) ) {
				printf("Setting data path to %s\n", argv[i+1]);
				strncpy(dpathbuf, argv[i+1], PATH_BUF_SIZE);
			}
			else {
				throw_error("path location invalid");
			}
		}
	}
}
/**
 * Initialize Socket.IO, bind event listener and connect to server.
 * @param url Server's URL.
 */
void ServerConnector::initialize_socketio(const std::string& url) {
  // Bind basic event to Socket.IO.
  client.set_close_listener(std::bind(&ServerConnector::on_close, this));
  client.set_fail_listener(std::bind(&ServerConnector::on_fail, this));
  client.set_open_listener(std::bind(&ServerConnector::on_open, this));

  client.connect(url);
  {
    std::lock_guard<std::mutex> guard(sio_mutex);
    if (status == ServerStatus::SETUP) {
      sio_cond.wait(sio_mutex);
    }
  }

  if (status == ServerStatus::APPROACH1) {
    socket = client.socket();

  } else {
    throw_error(Error::NETWORK);
  }

  // Bind 'on' event to Socket.IO.
#define M_BIND_SOCKETIO_EVENT(_name) {                                  \
    socket->on(_name,                                                   \
               [&](sio::event& event) {                                 \
                 std::lock_guard<std::mutex> guard(sio_mutex);          \
                 sio_queue.push(make_pair(_name, event.get_message())); \
                 uv_async_send(&async_receive);                         \
               });                                                      \
  }

  M_BIND_SOCKETIO_EVENT("sys_error");
  M_BIND_SOCKETIO_EVENT("app_error");
  M_BIND_SOCKETIO_EVENT("connect_node");
  M_BIND_SOCKETIO_EVENT("bind_node");
  M_BIND_SOCKETIO_EVENT("relay_command");
  M_BIND_SOCKETIO_EVENT("test_console");

#undef M_BIND_SOCKETIO_EVENT
}
Beispiel #27
0
int process_rotate_general(Stack s, int n, PROCESSOR_RESULT result) {
	double theta, x, y;
	StackItem *cur;
	if (stack_size(s) < 2 * n + 1) {
		return throw_error("Impossivel realizar operação. Motivo: há menos elementos na pilha do que o necessário (stack underflow).\n", result);
	}

	theta = stack_pop(s);
	
	cur = s->next;
	for (int i = 0; i < n; i++) {
		y = cur->value;
		x = cur->next->value;

		cur->value = (x * sin(theta) + y * cos(theta)); // calculate new y
		cur->next->value = (x * cos(theta) - y * sin(theta)); // calculate new x

		cur = cur->next->next;
	}

	return PROCESSOR_SUCCESS;
}
Beispiel #28
0
// Thread is started
void Thread::start()
{
    auto existed = (Thread *) std_get_tls_data(m_thread_tls_id);
    if (existed)
        throw_error("There was a structure binded to this thread.\n");

    // Bind this
    std_set_tls_data(m_thread_tls_id, this);

    // Create a domain for this thread
    char buf[64];
    snprintf(buf, sizeof(buf), "ThreadDomain(%llx)", (Int64)std_get_current_task_id());
    buf[sizeof(buf) - 1] = 0;
    m_start_domain = XNEW(Domain, buf);
    switch_domain(m_start_domain);

    // Create a domain context for this thread
    // Calculate the start sp of this thread (alignment to 4K)
    void *start_sp = (Uint8 *)m_get_stack_pointer_func() + 8 * sizeof(size_t);
    start_sp = (void *)(((size_t)start_sp | 0xFFF) + 1);
    push_domain_context(start_sp);
}
Beispiel #29
0
int		main(int argc, char **argv)
{
	int **tab;
	int **tab_rev;

	tab = alloc_tab();
	tab_rev = alloc_tab();
	if (argc != 10)
		return (throw_error());
	if (!populate_tab(tab, argc, argv))
		return (0);
	populate_tab(tab_rev, argc, argv);
	find_solution(tab, 0, 0, 0);
	find_solution(tab_rev, 0, 0, 1);
	if (compare_solution(tab, tab_rev))
		print_tab(tab);
	else
		ft_putstr("Erreur\n");
	free_tab(tab);
	free_tab(tab_rev);
	return (0);
}
Beispiel #30
0
VALUE mc_set(int argc, VALUE *argv, VALUE self) {
  memcached_st *mc;
  VALUE key, value, expiry, flags;
  static memcached_return_t result;

  Data_Get_Struct(self, memcached_st, mc);
  rb_scan_args(argc, argv, "22", &key, &value, &expiry, &flags);

  key = StringValue(key);
  if (!use_binary(mc)) key = escape_key(key, NULL);
  value = StringValue(value);

  result = memcached_set(mc, RSTRING_PTR(key), RSTRING_LEN(key), RSTRING_PTR(value), RSTRING_LEN(value),
                        RTEST(expiry) ? NUM2UINT(expiry) : 0,
                        RTEST(flags)  ? NUM2UINT(flags)  : 0);

  if (result == MEMCACHED_SUCCESS) {
    return value;
  } else {
    return throw_error(&result);
  }
}