Sync develop with master #4

Merged
RoshanSyed merged 144 commits from master into develop 2019-12-16 15:20:56 +00:00
7 changed files with 0 additions and 212 deletions
Showing only changes of commit 326140a931 - Show all commits

2
.gitignore vendored
View file

@ -50,5 +50,3 @@ GitSHA3.cpp
ntp_test
task_cancel_test
udt_client
udt_server

View file

@ -32,7 +32,6 @@ namespace fc
invalid_operation_exception_code = 14,
unknown_host_exception_code = 15,
null_optional_code = 16,
udt_error_code = 17,
aes_error_code = 18,
overflow_code = 19,
underflow_code = 20,
@ -294,7 +293,6 @@ namespace fc
FC_DECLARE_EXCEPTION( assert_exception, assert_exception_code, "Assert Exception" );
FC_DECLARE_EXCEPTION( eof_exception, eof_exception_code, "End Of File" );
FC_DECLARE_EXCEPTION( null_optional, null_optional_code, "null optional" );
FC_DECLARE_EXCEPTION( udt_exception, udt_error_code, "UDT error" );
FC_DECLARE_EXCEPTION( aes_exception, aes_error_code, "AES error" );
FC_DECLARE_EXCEPTION( overflow_exception, overflow_code, "Integer Overflow" );
FC_DECLARE_EXCEPTION( underflow_exception, underflow_code, "Integer Underflow" );

View file

@ -21,7 +21,6 @@ namespace fc
(eof_exception)
(unknown_host_exception)
(null_optional)
(udt_exception)
(aes_exception)
(overflow_exception)
(underflow_exception)

View file

@ -1,36 +0,0 @@
#include <iostream>
#include <udt.h>
#include <arpa/inet.h>
using namespace std;
using namespace UDT;
int main()
{
UDTSOCKET client = UDT::socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(9000);
inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
memset(&(serv_addr.sin_zero), '\0', 8);
// connect to the server, implict bind
if (UDT::ERROR == UDT::connect(client, (sockaddr*)&serv_addr, sizeof(serv_addr)))
{
cout << "connect: " << UDT::getlasterror().getErrorMessage();
return 0;
}
char* hello = "hello world! 3\n";
if (UDT::ERROR == UDT::send(client, hello, strlen(hello) + 1, 0))
{
cout << "send: " << UDT::getlasterror().getErrorMessage();
return 0;
}
UDT::close(client);
return 1;
}

View file

@ -1,83 +0,0 @@
#include <arpa/inet.h>
#include <udt.h>
#include <iostream>
using namespace std;
int main( int argc, char** argv )
{
UDTSOCKET serv = UDT::socket(AF_INET, SOCK_STREAM, 0);
bool block = false;
sockaddr_in my_addr;
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(9000);
my_addr.sin_addr.s_addr = INADDR_ANY;
memset(&(my_addr.sin_zero), '\0', 8);
if (UDT::ERROR == UDT::bind(serv, (sockaddr*)&my_addr, sizeof(my_addr)))
{
cout << "bind: " << UDT::getlasterror().getErrorMessage();
return 0;
}
UDT::listen(serv, 10);
int namelen;
sockaddr_in their_addr;
UDT::setsockopt(serv, 0, UDT_SNDSYN, &block, sizeof(bool));
UDT::setsockopt(serv, 0, UDT_RCVSYN, &block, sizeof(bool));
UDTSOCKET recver = UDT::accept(serv, (sockaddr*)&their_addr, &namelen);
if( recver == UDT::INVALID_SOCK )
{
if( UDT::getlasterror_code() == CUDTException::EASYNCRCV )
{
std::cout << "nothing yet... better luck next time\n";
}
}
auto pollid = UDT::epoll_create();
UDT::epoll_add_usock(pollid, serv, nullptr );// const int* events = NULL);
std::set<UDTSOCKET> readready;
std::set<UDTSOCKET> writeready;
std::cout << "waiting for 5 seconds\n";
UDT::epoll_wait( pollid, &readready, &writeready, 10000 );
recver = UDT::accept(serv, (sockaddr*)&their_addr, &namelen);
if( recver == UDT::INVALID_SOCK )
{
if( UDT::getlasterror_code() == CUDTException::EASYNCRCV )
{
std::cout << "nothing yet... better luck next time\n";
}
return 0;
}
UDT::setsockopt(recver, 0, UDT_SNDSYN, &block, sizeof(bool));
UDT::setsockopt(recver, 0, UDT_RCVSYN, &block, sizeof(bool));
UDT::epoll_remove_usock(pollid, serv );// const int* events = NULL);
int events = UDT_EPOLL_IN;
UDT::epoll_add_usock(pollid, recver, &events );// const int* events = NULL);
readready.clear();
UDT::epoll_wait( pollid, &readready, &writeready, 5000 );
char ip[16];
cout << "new connection: " << inet_ntoa(their_addr.sin_addr) << ":" << ntohs(their_addr.sin_port) << endl;
char data[100];
while (UDT::ERROR == UDT::recv(recver, data, 100, 0))
{
cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl;
UDT::epoll_wait( pollid, &readready, &writeready, 5000 );
}
cout << data << endl;
UDT::close(recver);
UDT::close(serv);
return 1;
}

View file

@ -1,49 +0,0 @@
#include <fc/network/udt_socket.hpp>
#include <fc/network/ip.hpp>
#include <fc/exception/exception.hpp>
#include <fc/thread/thread.hpp>
#include <iostream>
#include <vector>
using namespace fc;
int main( int argc, char** argv )
{
try {
udt_socket sock;
sock.bind( fc::ip::endpoint::from_string( "127.0.0.1:6666" ) );
ilog( "." );
sock.connect_to( fc::ip::endpoint::from_string( "127.0.0.1:7777" ) );
ilog( "after connect to..." );
std::cout << "local endpoint: " <<std::string( sock.local_endpoint() ) <<"\n";
std::cout << "remote endpoint: " <<std::string( sock.remote_endpoint() ) <<"\n";
std::string hello = "hello world\n";
for( uint32_t i = 0; i < 1000000; ++i )
{
sock.write( hello.c_str(), hello.size() );
}
ilog( "closing" );
sock.close();
usleep( fc::seconds(1) );
/*
std::vector<char> response;
response.resize(1024);
int r = sock.readsome( response.data(), response.size() );
while( r )
{
std::cout.write( response.data(), r );
r = sock.readsome( response.data(), response.size() );
}
*/
// if we exit too quickly, UDT will not have a chance to
// send the graceful close message.
//fc::usleep( fc::seconds(1) );
} catch ( const fc::exception& e )
{
elog( "${e}", ("e",e.to_detail_string() ) );
}
return 0;
}

View file

@ -1,39 +0,0 @@
#include <fc/network/udt_socket.hpp>
#include <fc/network/ip.hpp>
#include <fc/exception/exception.hpp>
#include <iostream>
#include <vector>
using namespace fc;
int main( int argc, char** argv )
{
try {
udt_server serv;
serv.listen( fc::ip::endpoint::from_string( "127.0.0.1:7777" ) );
while( true )
{
udt_socket sock;
serv.accept( sock );
std::vector<char> response;
response.resize(1024);
int r = sock.readsome( response.data(), response.size() );
while( r )
{
std::cout.write( response.data(), r );
r = sock.readsome( response.data(), response.size() );
//sock.write( response.data(), response.size() );
}
std::string goodbye = "goodbye cruel world";
sock.write( goodbye.c_str(), goodbye.size() );
}
} catch ( const fc::exception& e )
{
elog( "${e}", ("e",e.to_detail_string() ) );
}
return 0;
}