예제 #1
0
std::size_t SampleTestClient::send_data(tcp::socket& socket, int t_length)
{
    ptime       t1,t2;
    double      tdiff=0;
    double      last_status = 0;

    std::size_t h_sent=0;
    std::size_t ret=0;

    boost::array<char, DATASIZE>    data;
    boost::system::error_code       error;

    t1 = get_pts();
    t2 = t1;
    h_sent = 0;

    while ( get_diff(t1,t2) < t_length ) {
        ret = socket.send(boost::asio::buffer(data), 0, error);
        if ( ret == 0 ) {
            if ( error && error != boost::asio::error::eof) {
                std::cout << error.message() << std::endl;
            }
            break;
        }
        h_sent += ret;
        t2 = get_pts();
        tdiff = get_diff(t1, t2);
        if ( last_status + 1 < tdiff ) {
            status(tdiff, h_sent);
            last_status = tdiff;
        }
    }
    status(tdiff, h_sent);
    return h_sent;
}
예제 #2
0
파일: main.cpp 프로젝트: jbreams/nfldap
void sendResponse(tcp::socket& sock, uint64_t messageId, Ber::Packet response) {
    Ber::Packet envelope(
        Ber::Type::Constructed, Ber::Class::Universal, Ber::Tag::Sequence);
    envelope.appendChild(Ber::Packet(Ber::Tag::Integer, messageId));
    envelope.appendChild(response);

    std::vector<uint8_t> bytes;
    bytes.reserve(envelope.length());
    envelope.copyBytes(bytes);
    sock.send(asio::buffer(bytes));
}
예제 #3
0
bool
sendMessage(tcp::socket &socket, boost::shared_ptr<NetPacket> packet)
{
	bool retVal = false;
	if (packet) {
		uint32_t packetSize = packet->GetMsg()->ByteSize();
		google::protobuf::uint8 *buf = new google::protobuf::uint8[packetSize + NET_HEADER_SIZE];
		*((uint32_t *)buf) = htonl(packetSize);
		packet->GetMsg()->SerializeWithCachedSizesToArray(&buf[NET_HEADER_SIZE]);
		retVal = socket.send(boost::asio::buffer(buf, packetSize + NET_HEADER_SIZE)) != 0;
		delete[] buf;
	}
	return retVal;
}
예제 #4
0
int SampleTestClient::send_value(tcp::socket& socket, uint32_t value) {
    boost::system::error_code       error;
    uint32_t                        n_value=0;
    int                             ret=0;
    n_value = htonl(value); 
    ret = socket.send(boost::asio::buffer(&n_value, sizeof(n_value)), 0, error);
    if ( ret != sizeof(uint32_t) ) {
        if ( error && error != boost::asio::error::eof) {
            std::cout << error.message() << std::endl;
        }
        return -1;
    }
    return OK;
}
예제 #5
0
/* returns success or failure. */
int SampleTestClient::sure_send(tcp::socket& socket, const void *data, std::size_t size) {

    boost::system::error_code       error;
    std::size_t                     ret = 0;

    ret = socket.send(boost::asio::buffer(data, size), 0, error);
    if ( ret != size ) {
        if ( error && error != boost::asio::error::eof) {
            std::cout << error.message() << std::endl;
        }
        return -1;
    }
    return OK;

}