Beispiel #1
0
int Server::read_session(Session *sess){
	Link *link = sess->link;
	if(link->error()){
		return 0;
	}
	
	int len = link->read();
	if(len <= 0){
		this->close_session(sess);
		return -1;
	}
	
	while(1){
		Request req;
		int ret = link->recv(&req.msg);
		if(ret == -1){
			log_info("fd: %d, parse error, delete link", link->fd());
			this->close_session(sess);
			return -1;
		}else if(ret == 0){
			// 报文未就绪, 继续读网络
			break;
		}
		req.stime = millitime();
		req.sess = *sess;

		Response resp;
		for(int i=0; i<this->handlers.size(); i++){
			Handler *handler = this->handlers[i];
			req.time_wait = 1000 * (millitime() - req.stime);
			HandlerState state = handler->proc(req, &resp);
			req.time_proc = 1000 * (millitime() - req.stime) - req.time_wait;
			if(state == HANDLE_RESP){
				link->send(resp.msg);
				if(link && !link->output.empty()){
					fdes->set(link->fd(), FDEVENT_OUT, DEFAULT_TYPE, sess);
				}
				
				if(log_level() >= Logger::LEVEL_DEBUG){
					log_debug("w:%.3f,p:%.3f, req: %s resp: %s",
						req.time_wait, req.time_proc,
						msg_str(req.msg).c_str(),
						msg_str(resp.msg).c_str());
				}
			}else if(state == HANDLE_FAIL){
				this->close_session(sess);
				return -1;
			}
		}
	}

	return 0;
}
Beispiel #2
0
bool dake::gl::shader::compile(void)
{
    check_valid();

    glCompileShader(id);

    GLint status;
    glGetShaderiv(id, GL_COMPILE_STATUS, &status);
    if (status == GL_TRUE) {
        compiled = true;
        return true;
    }

    GLint illen;
    glGetShaderiv(id, GL_INFO_LOG_LENGTH, &illen);

    if (illen <= 1) {
        throw std::runtime_error("Error compiling " + std::string(shader_type_string(t)) + " shader " + name + ": Reason unknown");
    } else {
        char *msg = new char[illen + 1];

        glGetShaderInfoLog(id, illen, nullptr, msg);
        msg[illen] = 0;

        std::string msg_str(msg);
        delete[] msg;

        throw std::runtime_error("Error compiling " + std::string(shader_type_string(t)) + " shader " + name + ": " + msg_str);
    }

    return false;
}
Beispiel #3
0
bool dake::gl::program::link(void)
{
    check_valid();

    glLinkProgram(id);

    GLint status;
    glGetProgramiv(id, GL_LINK_STATUS, &status);
    if (status == GL_TRUE) {
        linked = true;
        return true;
    }

    GLint illen;
    glGetProgramiv(id, GL_INFO_LOG_LENGTH, &illen);

    if (illen <= 1) {
        throw std::runtime_error("Error linking shaders " + name + " to program: Reason unknown");
    } else {
        char *msg = new char[illen + 1];

        glGetProgramInfoLog(id, illen, nullptr, msg);
        msg[illen] = 0;

        std::string msg_str(msg);
        delete[] msg;

        throw std::runtime_error("Error linking shaders " + name + " to program: " + msg_str);
    }
}
int main (int argc, char **argv) 
{ 
    zmq::context_t context(1);
    zmq::socket_t socket(context, ZMQ_SUB);
    socket.bind("ipc:///tmp/to_app.ipc");
    socket.setsockopt(ZMQ_SUBSCRIBE, "", 0); 
    
    int rxcount = 0; 
    while (!stop) { 
        zmq::message_t msg; 
        try {
            socket.recv(&msg); 
        } catch (zmq::error_t& e) { 
            exit(1); 
        }
        std::vector<uint8_t> msg_buf(msg.size()); 
        std::memcpy(msg_buf.data(), msg.data(), msg.size()); 
        
        std::string msg_str(msg_buf.begin(), msg_buf.end()); 
        
        HelperRecv recvable =
		HelperRecvBuilder()
			.fromJson(msg_str)
			.build();
        
        rxcount++; 
        printf("recv'd message [rx count = %d] \n", rxcount); 
        printf("JSON: %s \n", msg_str.c_str()); 
        printf("message payload: %s \n", recvable.payload.c_str()); 
	    printf("\n"); 
    } 
    
    return 0; 
} 
const std::string task4_4::a_message::str() const
{
	std::string msg_str("a_message(");
	for (size_t i = 0; i < content_size; ++i)
		msg_str.push_back(content_[i]);
	msg_str.push_back(')');
	return msg_str;
}
Beispiel #6
0
static void do_waiters(char *name, struct summary *sum)
{
	FILE *file;
	char path[PATH_MAX];
	char line[LOCK_LINE_MAX];
	char rname[DLM_RESNAME_MAXLEN+1];
	int header = 0;
	int i, j, spaces;
	int rv, nodeid, wait_type;
	uint32_t id;

	snprintf(path, PATH_MAX, "/sys/kernel/debug/dlm/%s_waiters", name);

	file = fopen(path, "r");
	if (!file)
		return;

	while (fgets(line, LOCK_LINE_MAX, file)) {
		if (!header) {
			printf("\n");
			printf("Expecting reply\n");
			header = 1;
		}

		rv = sscanf(line, "%x %d %d",
			    &id, &wait_type, &nodeid);

		if (rv != 3) {
			printf("waiters: %s", line);
			continue;
		}

		/* parse the resource name from the remainder of the line */
		j = 0;
		spaces = 0;
		memset(rname, 0, sizeof(rname));

		for (i = 0; i < LOCK_LINE_MAX; i++) {
			if (line[i] == '\n')
				break;
			if (spaces == 3) {
				rname[j++] = line[i];
				if (j == (sizeof(rname) - 1))
					break;
			} else if (line[i] == ' ') {
				spaces++;
			}
		}

		printf("nodeid %2d msg %s lkid %08x resource \"%s\"\n",
		       nodeid, msg_str(wait_type), id, rname);

		sum->expect_replies++;
	}
	fclose(file);
}
    Control ControlReceiver::receiveControl() {
        vss_control::User_Control userControl;

        zmq::message_t request;
        socket->recv( &request, 0 );

        std::string msg_str( static_cast<char*>(request.data()), request.size());
        userControl.ParseFromString( msg_str );

        return vss::ControlMapper::userControlToControl(userControl);
    }
Beispiel #8
0
    inline bool check_std_vector_index(const char* function,
                                       const char* name,
                                       const std::vector<T>& y,
                                       int i) {
      if (i >= static_cast<int>(stan::error_index::value)
          && i < static_cast<int>(y.size() + stan::error_index::value))
        return true;

      std::stringstream msg;
      msg << " for " << name;
      std::string msg_str(msg.str());
      out_of_range(function, y.size(), i, msg_str.c_str());
      return false;
    }
Beispiel #9
0
 inline bool check_ldlt_factor(const char* function,
                               const char* name,
                               stan::math::LDLT_factor<T, R, C> &A) {
   if (!A.success()) {
     std::ostringstream msg;
     msg << "is not positive definite. "
         << "last conditional variance is ";
     std::string msg_str(msg.str());
     const T too_small = A.vectorD().tail(1)(0);
     domain_error(function, name, too_small,
                  msg_str.c_str(), ".");
     return false;
   }
   return true;
 }
Beispiel #10
0
    /**
     * Check if specified index is within range.
     *
     * This check is 1-indexed by default. This behavior can be
     * changed by setting <code>stan::error_index::value</code>.
     *
     * @param function Function name (for error messages)
     * @param name Variable name (for error messages)
     * @param max Maximum size of the variable
     * @param index Index to check
     * @param nested_level Nested level (for error messages)
     * @param error_msg Additional error message (for error messages)
     *
     * @throw <code>std::out_of_range</code> if the index is not in range
     */
    inline void check_range(const char* function,
                            const char* name,
                            int max,
                            int index,
                            int nested_level,
                            const char* error_msg) {
      if ((index >= stan::error_index::value)
          && (index < max + stan::error_index::value))
        return;

      std::stringstream msg;
      msg << "; index position = " << nested_level;
      std::string msg_str(msg.str());

      out_of_range(function, max, index, msg_str.c_str(), error_msg);
    }
Beispiel #11
0
    State StateReceiver::receiveState(FieldTransformationType userTransformation){
        vss_state::Global_State globalState;
        zmq::message_t request;

        socket->recv(&request, 0);
        std::string msg_str( static_cast<char*>(request.data()), request.size());

        globalState.ParseFromString(msg_str);
        auto state = StateMapper::globalStateToState(globalState);

        if (userTransformation == FieldTransformationType::Flip180Degrees) {
            state = CoordinateTransformer::spinField180Degrees(state);
        }

        return state;
    }
Beispiel #12
0
    inline bool check_row_index(const char* function,
                                const char* name,
                                const Eigen::Matrix<T_y, R, C>& y,
                                size_t i) {
      if (i >= stan::error_index::value
          && i < static_cast<size_t>(y.rows()) + stan::error_index::value)
        return true;

      std::stringstream msg;
      msg << " for rows of " << name;
      std::string msg_str(msg.str());
      out_of_range(function,
                   y.rows(),
                   i,
                   msg_str.c_str());
      return false;
    }
Beispiel #13
0
int main () {
    //  Prepare our context and socket
    zmq::context_t context (1);
	zmq::socket_t socket(context, ZMQ_PAIR);
    socket.bind ("tcp://*:5555");

    while (true) {
        zmq::message_t request;
        //  Wait for next request from client
        socket.recv (&request);
        std::cout << "Received" << std::endl;
        tutorial::Person person;
		std::string msg_str(static_cast<char*>(request.data()), request.size());
        person.ParseFromString(msg_str);
		std::string text_str;
		google::protobuf::TextFormat::PrintToString(person, &text_str);
		std::cout << text_str << std::endl;
    }
    return 0;
}
Beispiel #14
0
    inline bool check_vector(const char* function,
                             const char* name,
                             const Eigen::Matrix<T, R, C>& x) {
      if (R == 1)
        return true;
      if (C == 1)
        return true;
      if (x.rows() == 1 || x.cols() == 1)
        return true;

      std::ostringstream msg;
      msg << ") has " << x.rows() << " rows and "
          << x.cols() << " columns but it should be a vector so it should "
          << "either have 1 row or 1 column";
      std::string msg_str(msg.str());
      invalid_argument(function,
                       name,
                       typename scalar_type<T>::type(),
                       "(", msg_str.c_str());
      return false;
    }