You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by je...@apache.org on 2017/03/09 00:40:44 UTC

[1/2] nifi-minifi-cpp git commit: MINIFI-235: Use the appropriate connection when requested_hostname_ is not localhost

Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master 20bec6ca5 -> b6ada214a


MINIFI-235: Use the appropriate connection when requested_hostname_ is not localhost


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/a1f1d7c1
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/a1f1d7c1
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/a1f1d7c1

Branch: refs/heads/master
Commit: a1f1d7c1220f9696a9c7e7142a86e4def630ef89
Parents: 20bec6c
Author: Marc Parisi <ph...@apache.org>
Authored: Wed Mar 8 18:54:23 2017 -0500
Committer: Marc Parisi <ph...@apache.org>
Committed: Wed Mar 8 18:54:23 2017 -0500

----------------------------------------------------------------------
 libminifi/src/io/ClientSocket.cpp   | 23 ++++++++++++++---------
 libminifi/test/unit/SocketTests.cpp | 18 +++++++++---------
 2 files changed, 23 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a1f1d7c1/libminifi/src/io/ClientSocket.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/io/ClientSocket.cpp b/libminifi/src/io/ClientSocket.cpp
index fac5c9d..4f32eec 100644
--- a/libminifi/src/io/ClientSocket.cpp
+++ b/libminifi/src/io/ClientSocket.cpp
@@ -106,13 +106,18 @@ int8_t Socket::createConnection(const addrinfo *p) {
 		sa_loc->sin_family = AF_INET;
 		//sa_loc->sin_port = htons(port);
 		sa_loc->sin_port = htons(port_);
-		sa_loc->sin_addr.s_addr = htonl(INADDR_ANY); // inet_addr(requested_hostname.c_str());
+		// use any address if you are connecting to the local machine for testing
+		// otherwise we must use the requested hostname
+		if (IsNullOrEmpty(requested_hostname_) || requested_hostname_=="localhost")
+		  sa_loc->sin_addr.s_addr = htonl(INADDR_ANY);
+		else
+		  sa_loc->sin_addr.s_addr = inet_addr(requested_hostname_.c_str());
 		if (connect(socket_file_descriptor_, p->ai_addr, p->ai_addrlen) == -1) {
 			  close(socket_file_descriptor_);
 				socket_file_descriptor_ = -1;
 				logger_->log_warn("Could not connect to socket, error:%s", strerror(errno));
 				return -1;
-			
+
 		}
 	  }
 	}
@@ -142,7 +147,7 @@ short Socket::initialize() {
 	hints.ai_flags = AI_CANONNAME;
 	if (listeners_ > 0)
 	    hints.ai_flags |= AI_PASSIVE;
-	  
+
 	hints.ai_protocol = 0; /* any protocol */
 
 	int errcode = getaddrinfo(requested_hostname_.c_str(), 0, &hints, &addr_info_);
@@ -209,9 +214,9 @@ short Socket::select_descriptor(const uint16_t msec) {
 					socket_max_ = newfd;
 				}
 				return newfd;
-				
-				
-				
+
+
+
 			  }
 			  else{
 			    return socket_file_descriptor_;
@@ -289,7 +294,7 @@ int Socket::writeData(uint8_t *value, int size) {
 	while (bytes < size) {
 
 
-	  
+
 		ret = send(socket_file_descriptor_, value + bytes, size - bytes, 0);
 		//check for errors
 		if (ret <= 0) {
@@ -298,7 +303,7 @@ int Socket::writeData(uint8_t *value, int size) {
 			return ret;
 		}
 		bytes += ret;
-		
+
 	}
 
 	if (ret)
@@ -319,7 +324,7 @@ inline std::vector<uint8_t> Socket::readBuffer(const T& t) {
 
 
 int Socket::write(uint64_t base_value, bool is_little_endian){
-  
+
   return Serializable::write(base_value,this,is_little_endian);
 }
 

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/a1f1d7c1/libminifi/test/unit/SocketTests.cpp
----------------------------------------------------------------------
diff --git a/libminifi/test/unit/SocketTests.cpp b/libminifi/test/unit/SocketTests.cpp
index 39e8bb5..3fb7c9e 100644
--- a/libminifi/test/unit/SocketTests.cpp
+++ b/libminifi/test/unit/SocketTests.cpp
@@ -29,7 +29,7 @@ TEST_CASE("TestSocket", "[TestSocket1]") {
 
 TEST_CASE("TestSocketWriteTest1", "[TestSocket2]") {
 
-	Socket socket(Socket::getMyHostName(),8183);
+	Socket socket("localhost",8183);
 	REQUIRE(-1 == socket.initialize() );
 
 	socket.writeData(0,0);
@@ -48,11 +48,11 @@ TEST_CASE("TestSocketWriteTest2", "[TestSocket3]") {
 		std::vector<uint8_t> buffer;
 	buffer.push_back('a');
 
-	Socket server(Socket::getMyHostName(),9183,1);
+	Socket server("localhost",9183,1);
 
 	REQUIRE(-1 != server.initialize() );
 
-	Socket client(Socket::getMyHostName(),9183);
+	Socket client("localhost",9183);
 
 	REQUIRE(-1 != client.initialize() );
 
@@ -85,11 +85,11 @@ TEST_CASE("TestWriteEndian64", "[TestSocket4]") {
 		std::vector<uint8_t> buffer;
 	buffer.push_back('a');
 
-	Socket server(Socket::getMyHostName(),9183,1);
+	Socket server("localhost",9183,1);
 
 	REQUIRE(-1 != server.initialize() );
 
-	Socket client(Socket::getMyHostName(),9183);
+	Socket client("localhost",9183);
 
 	REQUIRE(-1 != client.initialize() );
 
@@ -115,11 +115,11 @@ TEST_CASE("TestWriteEndian32", "[TestSocket5]") {
 		std::vector<uint8_t> buffer;
 	buffer.push_back('a');
 
-	Socket server(Socket::getMyHostName(),9183,1);
+	Socket server("localhost",9183,1);
 
 	REQUIRE(-1 != server.initialize() );
 
-	Socket client(Socket::getMyHostName(),9183);
+	Socket client("localhost",9183);
 
 	REQUIRE(-1 != client.initialize() );
 
@@ -157,11 +157,11 @@ TEST_CASE("TestSocketWriteTestAfterClose", "[TestSocket6]") {
 		std::vector<uint8_t> buffer;
 	buffer.push_back('a');
 
-	Socket server(Socket::getMyHostName(),9183,1);
+	Socket server("localhost",9183,1);
 
 	REQUIRE(-1 != server.initialize() );
 
-	Socket client(Socket::getMyHostName(),9183);
+	Socket client("localhost",9183);
 
 	REQUIRE(-1 != client.initialize() );
 


[2/2] nifi-minifi-cpp git commit: MINIFI-235: Add curly braces per review

Posted by je...@apache.org.
MINIFI-235: Add curly braces per review

Signed-off-by: Jeremy Dyer <je...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/b6ada214
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/b6ada214
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/b6ada214

Branch: refs/heads/master
Commit: b6ada214ac0476128906c2b01c93f898ceaba515
Parents: a1f1d7c
Author: Marc Parisi <ph...@apache.org>
Authored: Wed Mar 8 19:12:45 2017 -0500
Committer: Jeremy Dyer <je...@apache.org>
Committed: Wed Mar 8 19:39:55 2017 -0500

----------------------------------------------------------------------
 libminifi/src/io/ClientSocket.cpp | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/b6ada214/libminifi/src/io/ClientSocket.cpp
----------------------------------------------------------------------
diff --git a/libminifi/src/io/ClientSocket.cpp b/libminifi/src/io/ClientSocket.cpp
index 4f32eec..ab391a4 100644
--- a/libminifi/src/io/ClientSocket.cpp
+++ b/libminifi/src/io/ClientSocket.cpp
@@ -109,9 +109,13 @@ int8_t Socket::createConnection(const addrinfo *p) {
 		// use any address if you are connecting to the local machine for testing
 		// otherwise we must use the requested hostname
 		if (IsNullOrEmpty(requested_hostname_) || requested_hostname_=="localhost")
+		{
 		  sa_loc->sin_addr.s_addr = htonl(INADDR_ANY);
+		}
 		else
+		{
 		  sa_loc->sin_addr.s_addr = inet_addr(requested_hostname_.c_str());
+		}
 		if (connect(socket_file_descriptor_, p->ai_addr, p->ai_addrlen) == -1) {
 			  close(socket_file_descriptor_);
 				socket_file_descriptor_ = -1;