You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by hc...@apache.org on 2014/11/18 10:02:34 UTC
[06/37] thrift git commit: THRIFT-2729: C++ - .clang-format created
and applied
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TPipe.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TPipe.h b/lib/cpp/src/thrift/transport/TPipe.h
index 2e4539c..ef957c6 100644
--- a/lib/cpp/src/thrift/transport/TPipe.h
+++ b/lib/cpp/src/thrift/transport/TPipe.h
@@ -23,11 +23,13 @@
#include <thrift/transport/TTransport.h>
#include <thrift/transport/TVirtualTransport.h>
#ifndef _WIN32
-# include <thrift/transport/TSocket.h>
+#include <thrift/transport/TSocket.h>
#endif
#include <boost/noncopyable.hpp>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
/**
* Windows Pipes implementation of the TTransport interface.
@@ -39,14 +41,14 @@ namespace apache { namespace thrift { namespace transport {
class TPipeImpl;
class TPipe : public TVirtualTransport<TPipe> {
- public:
+public:
// Constructs a new pipe object.
TPipe();
// Named pipe constructors -
- explicit TPipe(HANDLE Pipe); //HANDLE is a void*
- //need a const char * overload so string literals don't go to the HANDLE overload
- explicit TPipe(const char *pipename);
- explicit TPipe(const std::string &pipename);
+ explicit TPipe(HANDLE Pipe); // HANDLE is a void*
+ // need a const char * overload so string literals don't go to the HANDLE overload
+ explicit TPipe(const char* pipename);
+ explicit TPipe(const std::string& pipename);
// Anonymous pipe -
TPipe(HANDLE PipeRd, HANDLE PipeWrt);
@@ -71,21 +73,21 @@ class TPipe : public TVirtualTransport<TPipe> {
// Writes to the pipe.
virtual void write(const uint8_t* buf, uint32_t len);
-
- //Accessors
+ // Accessors
std::string getPipename();
- void setPipename(const std::string &pipename);
- HANDLE getPipeHandle(); //doubles as the read handle for anon pipe
+ void setPipename(const std::string& pipename);
+ HANDLE getPipeHandle(); // doubles as the read handle for anon pipe
void setPipeHandle(HANDLE pipehandle);
HANDLE getWrtPipeHandle();
void setWrtPipeHandle(HANDLE pipehandle);
long getConnectTimeout();
void setConnectTimeout(long seconds);
- //this function is intended to be used in generic / template situations,
- //so its name needs to be the same as TPipeServer's
+ // this function is intended to be used in generic / template situations,
+ // so its name needs to be the same as TPipeServer's
HANDLE getNativeWaitHandle();
- private:
+
+private:
boost::shared_ptr<TPipeImpl> impl_;
std::string pipename_;
@@ -97,8 +99,8 @@ class TPipe : public TVirtualTransport<TPipe> {
#else
typedef TSocket TPipe;
#endif
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
#endif // #ifndef _THRIFT_TRANSPORT_TPIPE_H_
-
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TPipeServer.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TPipeServer.cpp b/lib/cpp/src/thrift/transport/TPipeServer.cpp
index e14a94a..a8e72d0 100644
--- a/lib/cpp/src/thrift/transport/TPipeServer.cpp
+++ b/lib/cpp/src/thrift/transport/TPipeServer.cpp
@@ -26,12 +26,14 @@
#include <boost/noncopyable.hpp>
#ifdef _WIN32
-# include <thrift/windows/OverlappedSubmissionThread.h>
-# include <AccCtrl.h>
-# include <Aclapi.h>
+#include <thrift/windows/OverlappedSubmissionThread.h>
+#include <AccCtrl.h>
+#include <Aclapi.h>
#endif //_WIN32
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
#ifdef _WIN32
@@ -48,27 +50,27 @@ public:
virtual HANDLE getPipeHandle() = 0;
virtual HANDLE getWrtPipeHandle() = 0;
- virtual HANDLE getClientRdPipeHandle()= 0;
- virtual HANDLE getClientWrtPipeHandle()= 0;
- virtual HANDLE getNativeWaitHandle() {return NULL;}
+ virtual HANDLE getClientRdPipeHandle() = 0;
+ virtual HANDLE getClientWrtPipeHandle() = 0;
+ virtual HANDLE getNativeWaitHandle() { return NULL; }
};
class TAnonPipeServer : public TPipeServerImpl {
public:
- TAnonPipeServer()
- {
- //The anonymous pipe needs to be created first so that the server can
- //pass the handles on to the client before the serve (acceptImpl)
- //blocking call.
+ TAnonPipeServer() {
+ // The anonymous pipe needs to be created first so that the server can
+ // pass the handles on to the client before the serve (acceptImpl)
+ // blocking call.
if (!createAnonPipe()) {
GlobalOutput.perror("TPipeServer Create(Anon)Pipe failed, GLE=", GetLastError());
- throw TTransportException(TTransportException::NOT_OPEN, " TPipeServer Create(Anon)Pipe failed");
+ throw TTransportException(TTransportException::NOT_OPEN,
+ " TPipeServer Create(Anon)Pipe failed");
}
}
virtual ~TAnonPipeServer() {}
- virtual void interrupt() {} //not currently implemented
+ virtual void interrupt() {} // not currently implemented
virtual void close() {
PipeR_.reset();
PipeW_.reset();
@@ -78,17 +80,18 @@ public:
virtual boost::shared_ptr<TTransport> acceptImpl();
- virtual HANDLE getPipeHandle() {return PipeR_.h;}
- virtual HANDLE getWrtPipeHandle() {return PipeW_.h;}
- virtual HANDLE getClientRdPipeHandle() {return ClientAnonRead_.h;}
- virtual HANDLE getClientWrtPipeHandle() {return ClientAnonWrite_.h;}
+ virtual HANDLE getPipeHandle() { return PipeR_.h; }
+ virtual HANDLE getWrtPipeHandle() { return PipeW_.h; }
+ virtual HANDLE getClientRdPipeHandle() { return ClientAnonRead_.h; }
+ virtual HANDLE getClientWrtPipeHandle() { return ClientAnonWrite_.h; }
+
private:
bool createAnonPipe();
TAutoHandle PipeR_; // Anonymous Pipe (R)
TAutoHandle PipeW_; // Anonymous Pipe (W)
- //Client side anonymous pipe handles
+ // Client side anonymous pipe handles
//? Do we need duplicates to send to client?
TAutoHandle ClientAnonRead_;
TAutoHandle ClientAnonWrite_;
@@ -96,26 +99,18 @@ private:
class TNamedPipeServer : public TPipeServerImpl {
public:
- TNamedPipeServer(
- const std::string &pipename,
- uint32_t bufsize,
- uint32_t maxconnections) :
- stopping_(false),
- pipename_(pipename),
- bufsize_(bufsize),
- maxconns_(maxconnections)
- {
+ TNamedPipeServer(const std::string& pipename, uint32_t bufsize, uint32_t maxconnections)
+ : stopping_(false), pipename_(pipename), bufsize_(bufsize), maxconns_(maxconnections) {
connectOverlap_.action = TOverlappedWorkItem::CONNECT;
cancelOverlap_.action = TOverlappedWorkItem::CANCELIO;
initiateNamedConnect();
}
virtual ~TNamedPipeServer() {}
- virtual void interrupt()
- {
+ virtual void interrupt() {
TAutoCrit lock(pipe_protect_);
cached_client_.reset();
- if(Pipe_.h != INVALID_HANDLE_VALUE) {
+ if (Pipe_.h != INVALID_HANDLE_VALUE) {
stopping_ = true;
cancelOverlap_.h = Pipe_.h;
// This should wake up GetOverlappedResult
@@ -124,17 +119,16 @@ public:
}
}
- virtual void close() {
- Pipe_.reset();
- }
+ virtual void close() { Pipe_.reset(); }
virtual boost::shared_ptr<TTransport> acceptImpl();
- virtual HANDLE getPipeHandle() {return Pipe_.h;}
- virtual HANDLE getWrtPipeHandle() {return INVALID_HANDLE_VALUE;}
- virtual HANDLE getClientRdPipeHandle() {return INVALID_HANDLE_VALUE;}
- virtual HANDLE getClientWrtPipeHandle() {return INVALID_HANDLE_VALUE;}
- virtual HANDLE getNativeWaitHandle() {return listen_event_.h;}
+ virtual HANDLE getPipeHandle() { return Pipe_.h; }
+ virtual HANDLE getWrtPipeHandle() { return INVALID_HANDLE_VALUE; }
+ virtual HANDLE getClientRdPipeHandle() { return INVALID_HANDLE_VALUE; }
+ virtual HANDLE getClientWrtPipeHandle() { return INVALID_HANDLE_VALUE; }
+ virtual HANDLE getNativeWaitHandle() { return listen_event_.h; }
+
private:
bool createNamedPipe();
void initiateNamedConnect();
@@ -153,61 +147,50 @@ private:
TCriticalSection pipe_protect_;
};
-HANDLE TPipeServer::getNativeWaitHandle()
-{
- if(impl_) return impl_->getNativeWaitHandle();
+HANDLE TPipeServer::getNativeWaitHandle() {
+ if (impl_)
+ return impl_->getNativeWaitHandle();
return NULL;
}
//---- Constructors ----
-TPipeServer::TPipeServer(const std::string &pipename, uint32_t bufsize) :
- bufsize_(bufsize),
- isAnonymous_(false)
-{
+TPipeServer::TPipeServer(const std::string& pipename, uint32_t bufsize)
+ : bufsize_(bufsize), isAnonymous_(false) {
setMaxConnections(TPIPE_SERVER_MAX_CONNS_DEFAULT);
setPipename(pipename);
}
-TPipeServer::TPipeServer(const std::string &pipename, uint32_t bufsize, uint32_t maxconnections) :
- bufsize_(bufsize),
- isAnonymous_(false)
-{
+TPipeServer::TPipeServer(const std::string& pipename, uint32_t bufsize, uint32_t maxconnections)
+ : bufsize_(bufsize), isAnonymous_(false) {
setMaxConnections(maxconnections);
setPipename(pipename);
}
-TPipeServer::TPipeServer(const std::string &pipename) :
- bufsize_(1024),
- isAnonymous_(false)
-{
+TPipeServer::TPipeServer(const std::string& pipename) : bufsize_(1024), isAnonymous_(false) {
setMaxConnections(TPIPE_SERVER_MAX_CONNS_DEFAULT);
setPipename(pipename);
}
-TPipeServer::TPipeServer(int bufsize) :
- bufsize_(bufsize),
- isAnonymous_(true)
-{
+TPipeServer::TPipeServer(int bufsize) : bufsize_(bufsize), isAnonymous_(true) {
setMaxConnections(1);
impl_.reset(new TAnonPipeServer);
}
-TPipeServer::TPipeServer() :
- bufsize_(1024),
- isAnonymous_(true)
-{
+TPipeServer::TPipeServer() : bufsize_(1024), isAnonymous_(true) {
setMaxConnections(1);
impl_.reset(new TAnonPipeServer);
}
//---- Destructor ----
-TPipeServer::~TPipeServer() {}
+TPipeServer::~TPipeServer() {
+}
//---------------------------------------------------------
// Transport callbacks
//---------------------------------------------------------
void TPipeServer::listen() {
- if(isAnonymous_) return;
+ if (isAnonymous_)
+ return;
impl_.reset(new TNamedPipeServer(pipename_, bufsize_, maxconns_));
}
@@ -216,26 +199,27 @@ shared_ptr<TTransport> TPipeServer::acceptImpl() {
}
shared_ptr<TTransport> TAnonPipeServer::acceptImpl() {
- //This 0-byte read serves merely as a blocking call.
+ // This 0-byte read serves merely as a blocking call.
byte buf;
DWORD br;
- int fSuccess = ReadFile(
- PipeR_.h, // pipe handle
- &buf, // buffer to receive reply
- 0, // size of buffer
- &br, // number of bytes read
- NULL); // not overlapped
-
- if ( !fSuccess && GetLastError() != ERROR_MORE_DATA ) {
+ int fSuccess = ReadFile(PipeR_.h, // pipe handle
+ &buf, // buffer to receive reply
+ 0, // size of buffer
+ &br, // number of bytes read
+ NULL); // not overlapped
+
+ if (!fSuccess && GetLastError() != ERROR_MORE_DATA) {
GlobalOutput.perror("TPipeServer unable to initiate pipe comms, GLE=", GetLastError());
- throw TTransportException(TTransportException::NOT_OPEN, " TPipeServer unable to initiate pipe comms");
+ throw TTransportException(TTransportException::NOT_OPEN,
+ " TPipeServer unable to initiate pipe comms");
}
shared_ptr<TPipe> client(new TPipe(PipeR_.h, PipeW_.h));
return client;
}
void TNamedPipeServer::initiateNamedConnect() {
- if (stopping_) return;
+ if (stopping_)
+ return;
if (!createNamedPipe()) {
GlobalOutput.perror("TPipeServer CreateNamedPipe failed, GLE=", GetLastError());
throw TTransportException(TTransportException::NOT_OPEN, " TPipeServer CreateNamedPipe failed");
@@ -250,8 +234,7 @@ void TNamedPipeServer::initiateNamedConnect() {
// Wait for the client to connect; if it succeeds, the
// function returns a nonzero value. If the function returns
// zero, GetLastError should return ERROR_PIPE_CONNECTED.
- if( connectOverlap_.success )
- {
+ if (connectOverlap_.success) {
GlobalOutput.printf("Client connected.");
cached_client_.reset(new TPipe(Pipe_.h));
Pipe_.release();
@@ -261,8 +244,7 @@ void TNamedPipeServer::initiateNamedConnect() {
}
DWORD dwErr = connectOverlap_.last_error;
- switch( dwErr)
- {
+ switch (dwErr) {
case ERROR_PIPE_CONNECTED:
GlobalOutput.printf("Client connected.");
cached_client_.reset(new TPipe(Pipe_.h));
@@ -271,68 +253,68 @@ void TNamedPipeServer::initiateNamedConnect() {
SetEvent(listen_event_.h);
return;
case ERROR_IO_PENDING:
- return; //acceptImpl will do the appropriate WaitForMultipleObjects
+ return; // acceptImpl will do the appropriate WaitForMultipleObjects
default:
GlobalOutput.perror("TPipeServer ConnectNamedPipe failed, GLE=", dwErr);
- throw TTransportException(TTransportException::NOT_OPEN, " TPipeServer ConnectNamedPipe failed");
+ throw TTransportException(TTransportException::NOT_OPEN,
+ " TPipeServer ConnectNamedPipe failed");
}
}
shared_ptr<TTransport> TNamedPipeServer::acceptImpl() {
{
TAutoCrit lock(pipe_protect_);
- if(cached_client_.get() != NULL)
- {
+ if (cached_client_.get() != NULL) {
shared_ptr<TPipe> client;
- //zero out cached_client, since we are about to return it.
+ // zero out cached_client, since we are about to return it.
client.swap(cached_client_);
- //kick off the next connection before returning
+ // kick off the next connection before returning
initiateNamedConnect();
- return client; //success!
+ return client; // success!
}
}
- if(Pipe_.h == INVALID_HANDLE_VALUE) {
- throw TTransportException(
- TTransportException::NOT_OPEN,
- "TNamedPipeServer: someone called accept on a closed pipe server");
+ if (Pipe_.h == INVALID_HANDLE_VALUE) {
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "TNamedPipeServer: someone called accept on a closed pipe server");
}
DWORD dwDummy = 0;
- if(GetOverlappedResult(Pipe_.h, &connectOverlap_.overlap, &dwDummy, TRUE))
- {
+ if (GetOverlappedResult(Pipe_.h, &connectOverlap_.overlap, &dwDummy, TRUE)) {
TAutoCrit lock(pipe_protect_);
GlobalOutput.printf("Client connected.");
shared_ptr<TPipe> client(new TPipe(Pipe_.h));
Pipe_.release();
- //kick off the next connection before returning
+ // kick off the next connection before returning
initiateNamedConnect();
- return client; //success!
+ return client; // success!
}
- //if we got here, then we are in an error / shutdown case
- DWORD gle = GetLastError(); //save error before doing cleanup
+ // if we got here, then we are in an error / shutdown case
+ DWORD gle = GetLastError(); // save error before doing cleanup
close();
GlobalOutput.perror("TPipeServer ConnectNamedPipe GLE=", gle);
throw TTransportException(TTransportException::NOT_OPEN, "TPipeServer: client connection failed");
}
void TPipeServer::interrupt() {
- if(impl_) impl_->interrupt();
+ if (impl_)
+ impl_->interrupt();
}
void TPipeServer::close() {
- if(impl_) impl_->close();
+ if (impl_)
+ impl_->close();
}
-
bool TNamedPipeServer::createNamedPipe() {
- //Windows - set security to allow non-elevated apps
- //to access pipes created by elevated apps.
+ // Windows - set security to allow non-elevated apps
+ // to access pipes created by elevated apps.
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
PSID everyone_sid = NULL;
- AllocateAndInitializeSid(&SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &everyone_sid);
+ AllocateAndInitializeSid(
+ &SIDAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &everyone_sid);
EXPLICIT_ACCESS ea;
ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
@@ -341,12 +323,12 @@ bool TNamedPipeServer::createNamedPipe() {
ea.grfInheritance = NO_INHERITANCE;
ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
- ea.Trustee.ptstrName = (LPSTR)everyone_sid;
+ ea.Trustee.ptstrName = (LPSTR)everyone_sid;
PACL acl = NULL;
SetEntriesInAcl(1, &ea, NULL, &acl);
- PSECURITY_DESCRIPTOR sd = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR,SECURITY_DESCRIPTOR_MIN_LENGTH);
+ PSECURITY_DESCRIPTOR sd = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(sd, TRUE, acl, FALSE);
@@ -356,23 +338,23 @@ bool TNamedPipeServer::createNamedPipe() {
sa.bInheritHandle = FALSE;
// Create an instance of the named pipe
- TAutoHandle hPipe(CreateNamedPipe(
- pipename_.c_str(), // pipe name
- PIPE_ACCESS_DUPLEX | // read/write access
- FILE_FLAG_OVERLAPPED, // async mode
- PIPE_TYPE_BYTE | // byte type pipe
- PIPE_READMODE_BYTE, // byte read mode
- maxconns_, // max. instances
- bufsize_, // output buffer size
- bufsize_, // input buffer size
- 0, // client time-out
- &sa)); // security attributes
-
- if(hPipe.h == INVALID_HANDLE_VALUE)
- {
+ TAutoHandle hPipe(CreateNamedPipe(pipename_.c_str(), // pipe name
+ PIPE_ACCESS_DUPLEX | // read/write access
+ FILE_FLAG_OVERLAPPED, // async mode
+ PIPE_TYPE_BYTE | // byte type pipe
+ PIPE_READMODE_BYTE, // byte read mode
+ maxconns_, // max. instances
+ bufsize_, // output buffer size
+ bufsize_, // input buffer size
+ 0, // client time-out
+ &sa)); // security attributes
+
+ if (hPipe.h == INVALID_HANDLE_VALUE) {
Pipe_.reset();
GlobalOutput.perror("TPipeServer::TCreateNamedPipe() GLE=", GetLastError());
- throw TTransportException(TTransportException::NOT_OPEN, "TCreateNamedPipe() failed", GetLastError());
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "TCreateNamedPipe() failed",
+ GetLastError());
return false;
}
@@ -382,21 +364,21 @@ bool TNamedPipeServer::createNamedPipe() {
bool TAnonPipeServer::createAnonPipe() {
SECURITY_ATTRIBUTES sa;
- SECURITY_DESCRIPTOR sd; //security information for pipes
+ SECURITY_DESCRIPTOR sd; // security information for pipes
- InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
+ InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, true, NULL, false);
sa.lpSecurityDescriptor = &sd;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
- sa.bInheritHandle = true; //allow passing handle to child
+ sa.bInheritHandle = true; // allow passing handle to child
HANDLE ClientAnonReadH, PipeW_H, ClientAnonWriteH, Pipe_H;
- if (!CreatePipe(&ClientAnonReadH,&PipeW_H,&sa,0)) //create stdin pipe
+ if (!CreatePipe(&ClientAnonReadH, &PipeW_H, &sa, 0)) // create stdin pipe
{
GlobalOutput.perror("TPipeServer CreatePipe (anon) failed, GLE=", GetLastError());
return false;
}
- if (!CreatePipe(&Pipe_H,&ClientAnonWriteH,&sa,0)) //create stdout pipe
+ if (!CreatePipe(&Pipe_H, &ClientAnonWriteH, &sa, 0)) // create stdout pipe
{
GlobalOutput.perror("TPipeServer CreatePipe (anon) failed, GLE=", GetLastError());
CloseHandle(ClientAnonReadH);
@@ -415,29 +397,46 @@ bool TAnonPipeServer::createAnonPipe() {
//---------------------------------------------------------
// Accessors
//---------------------------------------------------------
-string TPipeServer::getPipename() {return pipename_;}
+string TPipeServer::getPipename() {
+ return pipename_;
+}
-void TPipeServer::setPipename(const std::string &pipename) {
- if(pipename.find("\\\\") == -1)
+void TPipeServer::setPipename(const std::string& pipename) {
+ if (pipename.find("\\\\") == -1)
pipename_ = "\\\\.\\pipe\\" + pipename;
else
pipename_ = pipename;
}
-int TPipeServer::getBufferSize() {return bufsize_;}
-void TPipeServer::setBufferSize(int bufsize) {bufsize_ = bufsize;}
+int TPipeServer::getBufferSize() {
+ return bufsize_;
+}
+void TPipeServer::setBufferSize(int bufsize) {
+ bufsize_ = bufsize;
+}
-HANDLE TPipeServer::getPipeHandle() {return impl_?impl_->getPipeHandle() :INVALID_HANDLE_VALUE;}
-HANDLE TPipeServer::getWrtPipeHandle() {return impl_?impl_->getWrtPipeHandle() :INVALID_HANDLE_VALUE;}
-HANDLE TPipeServer::getClientRdPipeHandle() {return impl_?impl_->getClientRdPipeHandle() :INVALID_HANDLE_VALUE;}
-HANDLE TPipeServer::getClientWrtPipeHandle() {return impl_?impl_->getClientWrtPipeHandle():INVALID_HANDLE_VALUE;}
+HANDLE TPipeServer::getPipeHandle() {
+ return impl_ ? impl_->getPipeHandle() : INVALID_HANDLE_VALUE;
+}
+HANDLE TPipeServer::getWrtPipeHandle() {
+ return impl_ ? impl_->getWrtPipeHandle() : INVALID_HANDLE_VALUE;
+}
+HANDLE TPipeServer::getClientRdPipeHandle() {
+ return impl_ ? impl_->getClientRdPipeHandle() : INVALID_HANDLE_VALUE;
+}
+HANDLE TPipeServer::getClientWrtPipeHandle() {
+ return impl_ ? impl_->getClientWrtPipeHandle() : INVALID_HANDLE_VALUE;
+}
-bool TPipeServer::getAnonymous() { return isAnonymous_; }
-void TPipeServer::setAnonymous(bool anon) { isAnonymous_ = anon;}
+bool TPipeServer::getAnonymous() {
+ return isAnonymous_;
+}
+void TPipeServer::setAnonymous(bool anon) {
+ isAnonymous_ = anon;
+}
-void TPipeServer::setMaxConnections(uint32_t maxconnections)
-{
- if(maxconnections == 0)
+void TPipeServer::setMaxConnections(uint32_t maxconnections) {
+ if (maxconnections == 0)
maxconns_ = 1;
else if (maxconnections > PIPE_UNLIMITED_INSTANCES)
maxconns_ = PIPE_UNLIMITED_INSTANCES;
@@ -446,5 +445,6 @@ void TPipeServer::setMaxConnections(uint32_t maxconnections)
}
#endif //_WIN32
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TPipeServer.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TPipeServer.h b/lib/cpp/src/thrift/transport/TPipeServer.h
old mode 100755
new mode 100644
index 98ecde0..405793e
--- a/lib/cpp/src/thrift/transport/TPipeServer.h
+++ b/lib/cpp/src/thrift/transport/TPipeServer.h
@@ -23,15 +23,17 @@
#include <thrift/transport/TServerTransport.h>
#include <boost/shared_ptr.hpp>
#ifndef _WIN32
-# include <thrift/transport/TServerSocket.h>
+#include <thrift/transport/TServerSocket.h>
#endif
#ifdef _WIN32
-# include <thrift/windows/Sync.h>
+#include <thrift/windows/Sync.h>
#endif
#define TPIPE_SERVER_MAX_CONNS_DEFAULT PIPE_UNLIMITED_INSTANCES
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
/**
* Windows Pipes implementation of TServerTransport.
@@ -44,30 +46,30 @@ class TPipeServerImpl;
class TPipe;
class TPipeServer : public TServerTransport {
- public:
- //Constructors
+public:
+ // Constructors
// Named Pipe -
- TPipeServer(const std::string &pipename, uint32_t bufsize);
- TPipeServer(const std::string &pipename, uint32_t bufsize, uint32_t maxconnections);
- TPipeServer(const std::string &pipename);
+ TPipeServer(const std::string& pipename, uint32_t bufsize);
+ TPipeServer(const std::string& pipename, uint32_t bufsize, uint32_t maxconnections);
+ TPipeServer(const std::string& pipename);
// Anonymous pipe -
TPipeServer(int bufsize);
TPipeServer();
- //Destructor
+ // Destructor
virtual ~TPipeServer();
- //Standard transport callbacks
+ // Standard transport callbacks
virtual void interrupt();
virtual void close();
virtual void listen();
- //Accessors
+ // Accessors
std::string getPipename();
- void setPipename(const std::string &pipename);
- int getBufferSize();
+ void setPipename(const std::string& pipename);
+ int getBufferSize();
void setBufferSize(int bufsize);
- HANDLE getPipeHandle(); //Named Pipe R/W -or- Anonymous pipe Read handle
+ HANDLE getPipeHandle(); // Named Pipe R/W -or- Anonymous pipe Read handle
HANDLE getWrtPipeHandle();
HANDLE getClientRdPipeHandle();
HANDLE getClientWrtPipeHandle();
@@ -75,13 +77,14 @@ class TPipeServer : public TServerTransport {
void setAnonymous(bool anon);
void setMaxConnections(uint32_t maxconnections);
- //this function is intended to be used in generic / template situations,
- //so its name needs to be the same as TPipe's
+ // this function is intended to be used in generic / template situations,
+ // so its name needs to be the same as TPipe's
HANDLE getNativeWaitHandle();
+
protected:
virtual boost::shared_ptr<TTransport> acceptImpl();
- private:
+private:
boost::shared_ptr<TPipeServerImpl> impl_;
std::string pipename_;
@@ -93,7 +96,8 @@ protected:
//*NIX named pipe implementation uses domain socket
typedef TServerSocket TPipeServer;
#endif
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
#endif // #ifndef _THRIFT_TRANSPORT_TSERVERWINPIPES_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp b/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
index 45301f8..cf686e0 100644
--- a/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
@@ -20,26 +20,29 @@
#include <thrift/transport/TSSLServerSocket.h>
#include <thrift/transport/TSSLSocket.h>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
/**
* SSL server socket implementation.
*/
-TSSLServerSocket::TSSLServerSocket(THRIFT_SOCKET port,
- boost::shared_ptr<TSSLSocketFactory> factory):
- TServerSocket(port), factory_(factory) {
+TSSLServerSocket::TSSLServerSocket(THRIFT_SOCKET port, boost::shared_ptr<TSSLSocketFactory> factory)
+ : TServerSocket(port), factory_(factory) {
factory_->server(true);
}
-TSSLServerSocket::TSSLServerSocket(int port, int sendTimeout, int recvTimeout,
- boost::shared_ptr<TSSLSocketFactory> factory):
- TServerSocket(port, sendTimeout, recvTimeout),
- factory_(factory) {
+TSSLServerSocket::TSSLServerSocket(int port,
+ int sendTimeout,
+ int recvTimeout,
+ boost::shared_ptr<TSSLSocketFactory> factory)
+ : TServerSocket(port, sendTimeout, recvTimeout), factory_(factory) {
factory_->server(true);
}
boost::shared_ptr<TSocket> TSSLServerSocket::createSocket(THRIFT_SOCKET client) {
return factory_->createSocket(client);
}
-
-}}}
+}
+}
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TSSLServerSocket.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TSSLServerSocket.h b/lib/cpp/src/thrift/transport/TSSLServerSocket.h
index 3a4b44d..bb52b04 100644
--- a/lib/cpp/src/thrift/transport/TSSLServerSocket.h
+++ b/lib/cpp/src/thrift/transport/TSSLServerSocket.h
@@ -23,15 +23,17 @@
#include <boost/shared_ptr.hpp>
#include <thrift/transport/TServerSocket.h>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
class TSSLSocketFactory;
/**
* Server socket that accepts SSL connections.
*/
-class TSSLServerSocket: public TServerSocket {
- public:
+class TSSLServerSocket : public TServerSocket {
+public:
/**
* Constructor.
*
@@ -47,13 +49,17 @@ class TSSLServerSocket: public TServerSocket {
* @param recvTimeout Socket receive timeout
* @param factory SSL socket factory implementation
*/
- TSSLServerSocket(int port, int sendTimeout, int recvTimeout,
+ TSSLServerSocket(int port,
+ int sendTimeout,
+ int recvTimeout,
boost::shared_ptr<TSSLSocketFactory> factory);
- protected:
+
+protected:
boost::shared_ptr<TSocket> createSocket(THRIFT_SOCKET socket);
boost::shared_ptr<TSSLSocketFactory> factory_;
};
-
-}}}
+}
+}
+}
#endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TSSLSocket.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.cpp b/lib/cpp/src/thrift/transport/TSSLSocket.cpp
index fd285db..de5876c 100644
--- a/lib/cpp/src/thrift/transport/TSSLSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TSSLSocket.cpp
@@ -47,7 +47,9 @@ struct CRYPTO_dynlock_value {
Mutex mutex;
};
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
// OpenSSL initialization/cleanup
@@ -64,7 +66,7 @@ static void callbackLocking(int mode, int n, const char*, int) {
#if (OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_NO_THREAD_ID)
static unsigned long callbackThreadID() {
- return (unsigned long) pthread_self();
+ return (unsigned long)pthread_self();
}
#endif
@@ -72,9 +74,7 @@ static CRYPTO_dynlock_value* dyn_create(const char*, int) {
return new CRYPTO_dynlock_value;
}
-static void dyn_lock(int mode,
- struct CRYPTO_dynlock_value* lock,
- const char*, int) {
+static void dyn_lock(int mode, struct CRYPTO_dynlock_value* lock, const char*, int) {
if (lock != NULL) {
if (mode & CRYPTO_LOCK) {
lock->mutex.lock();
@@ -96,11 +96,11 @@ void initializeOpenSSL() {
SSL_library_init();
SSL_load_error_strings();
// static locking
- mutexes = boost::shared_array<Mutex>(new Mutex[::CRYPTO_num_locks()]);
+ mutexes = boost::shared_array<Mutex>(new Mutex[ ::CRYPTO_num_locks()]);
if (mutexes == NULL) {
throw TTransportException(TTransportException::INTERNAL_ERROR,
- "initializeOpenSSL() failed, "
- "out of memory while creating mutex array");
+ "initializeOpenSSL() failed, "
+ "out of memory while creating mutex array");
}
#if (OPENSSL_VERSION_NUMBER < OPENSSL_VERSION_NO_THREAD_ID)
CRYPTO_set_id_callback(callbackThreadID);
@@ -137,28 +137,17 @@ static char uppercase(char c);
// SSLContext implementation
SSLContext::SSLContext(const SSLProtocol& protocol) {
- if(protocol == SSLTLS)
- {
+ if (protocol == SSLTLS) {
ctx_ = SSL_CTX_new(SSLv23_method());
- }
- else if(protocol == SSLv3)
- {
+ } else if (protocol == SSLv3) {
ctx_ = SSL_CTX_new(SSLv3_method());
- }
- else if(protocol == TLSv1_0)
- {
+ } else if (protocol == TLSv1_0) {
ctx_ = SSL_CTX_new(TLSv1_method());
- }
- else if(protocol == TLSv1_1)
- {
+ } else if (protocol == TLSv1_1) {
ctx_ = SSL_CTX_new(TLSv1_1_method());
- }
- else if(protocol == TLSv1_2)
- {
+ } else if (protocol == TLSv1_2) {
ctx_ = SSL_CTX_new(TLSv1_2_method());
- }
- else
- {
+ } else {
/// UNKNOWN PROTOCOL!
throw TSSLException("SSL_CTX_new: Unknown protocol");
}
@@ -171,8 +160,7 @@ SSLContext::SSLContext(const SSLProtocol& protocol) {
SSL_CTX_set_mode(ctx_, SSL_MODE_AUTO_RETRY);
// Disable horribly insecure SSLv2!
- if(protocol == SSLTLS)
- {
+ if (protocol == SSLTLS) {
SSL_CTX_set_options(ctx_, SSL_OP_NO_SSLv2);
}
}
@@ -195,16 +183,16 @@ SSL* SSLContext::createSSL() {
}
// TSSLSocket implementation
-TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx):
- TSocket(), server_(false), ssl_(NULL), ctx_(ctx) {
+TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx)
+ : TSocket(), server_(false), ssl_(NULL), ctx_(ctx) {
}
-TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx, THRIFT_SOCKET socket):
- TSocket(socket), server_(false), ssl_(NULL), ctx_(ctx) {
+TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx, THRIFT_SOCKET socket)
+ : TSocket(socket), server_(false), ssl_(NULL), ctx_(ctx) {
}
-TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx, string host, int port):
- TSocket(host, port), server_(false), ssl_(NULL), ctx_(ctx) {
+TSSLSocket::TSSLSocket(boost::shared_ptr<SSLContext> ctx, string host, int port)
+ : TSocket(host, port), server_(false), ssl_(NULL), ctx_(ctx) {
}
TSSLSocket::~TSSLSocket() {
@@ -218,7 +206,7 @@ bool TSSLSocket::isOpen() {
int shutdown = SSL_get_shutdown(ssl_);
// "!!" is squelching C4800 "forcing bool -> true or false" perfomance warning
bool shutdownReceived = !!(shutdown & SSL_RECEIVED_SHUTDOWN);
- bool shutdownSent = !!(shutdown & SSL_SENT_SHUTDOWN);
+ bool shutdownSent = !!(shutdown & SSL_SENT_SHUTDOWN);
if (shutdownReceived && shutdownSent) {
return false;
}
@@ -274,7 +262,7 @@ void TSSLSocket::close() {
uint32_t TSSLSocket::read(uint8_t* buf, uint32_t len) {
checkHandshake();
int32_t bytes = 0;
- for (int32_t retries = 0; retries < maxRecvRetries_; retries++){
+ for (int32_t retries = 0; retries < maxRecvRetries_; retries++) {
bytes = SSL_read(ssl_, buf, len);
if (bytes >= 0)
break;
@@ -352,9 +340,8 @@ void TSSLSocket::checkHandshake() {
void TSSLSocket::authorize() {
int rc = SSL_get_verify_result(ssl_);
- if (rc != X509_V_OK) { // verify authentication result
- throw TSSLException(string("SSL_get_verify_result(), ") +
- X509_verify_cert_error_string(rc));
+ if (rc != X509_V_OK) { // verify authentication result
+ throw TSSLException(string("SSL_get_verify_result(), ") + X509_verify_cert_error_string(rc));
}
X509* cert = SSL_get_peer_certificate(ssl_);
@@ -395,8 +382,8 @@ void TSSLSocket::authorize() {
}
// extract subjectAlternativeName
- STACK_OF(GENERAL_NAME)* alternatives = (STACK_OF(GENERAL_NAME)*)
- X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL);
+ STACK_OF(GENERAL_NAME)* alternatives
+ = (STACK_OF(GENERAL_NAME)*)X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL);
if (alternatives != NULL) {
const int count = sk_GENERAL_NAME_num(alternatives);
for (int i = 0; decision == AccessManager::SKIP && i < count; i++) {
@@ -407,15 +394,15 @@ void TSSLSocket::authorize() {
char* data = (char*)ASN1_STRING_data(name->d.ia5);
int length = ASN1_STRING_length(name->d.ia5);
switch (name->type) {
- case GEN_DNS:
- if (host.empty()) {
- host = (server() ? getPeerHost() : getHost());
- }
- decision = access_->verify(host, data, length);
- break;
- case GEN_IPADD:
- decision = access_->verify(sa, data, length);
- break;
+ case GEN_DNS:
+ if (host.empty()) {
+ host = (server() ? getPeerHost() : getHost());
+ }
+ decision = access_->verify(host, data, length);
+ break;
+ case GEN_IPADD:
+ decision = access_->verify(sa, data, length);
+ break;
}
}
sk_GENERAL_NAME_pop_free(alternatives, GENERAL_NAME_free);
@@ -459,10 +446,10 @@ void TSSLSocket::authorize() {
// TSSLSocketFactory implementation
uint64_t TSSLSocketFactory::count_ = 0;
-Mutex TSSLSocketFactory::mutex_;
-bool TSSLSocketFactory::manualOpenSSLInitialization_ = false;
+Mutex TSSLSocketFactory::mutex_;
+bool TSSLSocketFactory::manualOpenSSLInitialization_ = false;
-TSSLSocketFactory::TSSLSocketFactory(const SSLProtocol& protocol): server_(false) {
+TSSLSocketFactory::TSSLSocketFactory(const SSLProtocol& protocol) : server_(false) {
Guard guard(mutex_);
if (count_ == 0) {
if (!manualOpenSSLInitialization_) {
@@ -495,8 +482,7 @@ boost::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(THRIFT_SOCKET sock
return ssl;
}
-boost::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(const string& host,
- int port) {
+boost::shared_ptr<TSSLSocket> TSSLSocketFactory::createSocket(const string& host, int port) {
boost::shared_ptr<TSSLSocket> ssl(new TSSLSocket(ctx_, host, port));
setup(ssl);
return ssl;
@@ -527,7 +513,7 @@ void TSSLSocketFactory::ciphers(const string& enable) {
void TSSLSocketFactory::authenticate(bool required) {
int mode;
if (required) {
- mode = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT | SSL_VERIFY_CLIENT_ONCE;
+ mode = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT | SSL_VERIFY_CLIENT_ONCE;
} else {
mode = SSL_VERIFY_NONE;
}
@@ -537,7 +523,7 @@ void TSSLSocketFactory::authenticate(bool required) {
void TSSLSocketFactory::loadCertificate(const char* path, const char* format) {
if (path == NULL || format == NULL) {
throw TTransportException(TTransportException::BAD_ARGS,
- "loadCertificateChain: either <path> or <format> is NULL");
+ "loadCertificateChain: either <path> or <format> is NULL");
}
if (strcmp(format, "PEM") == 0) {
if (SSL_CTX_use_certificate_chain_file(ctx_->get(), path) == 0) {
@@ -554,7 +540,7 @@ void TSSLSocketFactory::loadCertificate(const char* path, const char* format) {
void TSSLSocketFactory::loadPrivateKey(const char* path, const char* format) {
if (path == NULL || format == NULL) {
throw TTransportException(TTransportException::BAD_ARGS,
- "loadPrivateKey: either <path> or <format> is NULL");
+ "loadPrivateKey: either <path> or <format> is NULL");
}
if (strcmp(format, "PEM") == 0) {
if (SSL_CTX_use_PrivateKey_file(ctx_->get(), path, SSL_FILETYPE_PEM) == 0) {
@@ -569,7 +555,7 @@ void TSSLSocketFactory::loadPrivateKey(const char* path, const char* format) {
void TSSLSocketFactory::loadTrustedCertificates(const char* path) {
if (path == NULL) {
throw TTransportException(TTransportException::BAD_ARGS,
- "loadTrustedCertificates: <path> is NULL");
+ "loadTrustedCertificates: <path> is NULL");
}
if (SSL_CTX_load_verify_locations(ctx_->get(), path, NULL) == 0) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
@@ -588,10 +574,7 @@ void TSSLSocketFactory::overrideDefaultPasswordCallback() {
SSL_CTX_set_default_passwd_cb_userdata(ctx_->get(), this);
}
-int TSSLSocketFactory::passwordCallback(char* password,
- int size,
- int,
- void* data) {
+int TSSLSocketFactory::passwordCallback(char* password, int size, int, void* data) {
TSSLSocketFactory* factory = (TSSLSocketFactory*)data;
string userPassword;
factory->getPassword(userPassword, size);
@@ -605,8 +588,8 @@ int TSSLSocketFactory::passwordCallback(char* password,
// extract error messages from error queue
void buildErrors(string& errors, int errno_copy) {
- unsigned long errorCode;
- char message[256];
+ unsigned long errorCode;
+ char message[256];
errors.reserve(512);
while ((errorCode = ERR_get_error()) != 0) {
@@ -633,9 +616,8 @@ void buildErrors(string& errors, int errno_copy) {
/**
* Default implementation of AccessManager
*/
-Decision DefaultClientAccessManager::verify(const sockaddr_storage& sa)
- throw() {
- (void) sa;
+Decision DefaultClientAccessManager::verify(const sockaddr_storage& sa) throw() {
+ (void)sa;
return SKIP;
}
@@ -691,16 +673,16 @@ bool matchName(const char* host, const char* pattern, int size) {
match = true;
}
return match;
-
}
// This is to work around the Turkish locale issue, i.e.,
// toupper('i') != toupper('I') if locale is "tr_TR"
-char uppercase (char c) {
+char uppercase(char c) {
if ('a' <= c && c <= 'z') {
return c + ('A' - 'a');
}
return c;
}
-
-}}}
+}
+}
+}
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TSSLSocket.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TSSLSocket.h b/lib/cpp/src/thrift/transport/TSSLSocket.h
index a4b805b..8d4277a 100644
--- a/lib/cpp/src/thrift/transport/TSSLSocket.h
+++ b/lib/cpp/src/thrift/transport/TSSLSocket.h
@@ -26,21 +26,22 @@
#include <thrift/concurrency/Mutex.h>
#include <thrift/transport/TSocket.h>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
class AccessManager;
class SSLContext;
enum SSLProtocol {
- SSLTLS = 0, // Supports SSLv3 and TLSv1.
- //SSLv2 = 1, // HORRIBLY INSECURE!
- SSLv3 = 2, // Supports SSLv3 only.
- TLSv1_0 = 3, // Supports TLSv1_0 only.
- TLSv1_1 = 4, // Supports TLSv1_1 only.
- TLSv1_2 = 5 // Supports TLSv1_2 only.
+ SSLTLS = 0, // Supports SSLv3 and TLSv1.
+ // SSLv2 = 1, // HORRIBLY INSECURE!
+ SSLv3 = 2, // Supports SSLv3 only.
+ TLSv1_0 = 3, // Supports TLSv1_0 only.
+ TLSv1_1 = 4, // Supports TLSv1_1 only.
+ TLSv1_2 = 5 // Supports TLSv1_2 only.
};
-
/**
* Initialize OpenSSL library. This function, or some other
* equivalent function to initialize OpenSSL, must be called before
@@ -61,24 +62,24 @@ void cleanupOpenSSL();
/**
* OpenSSL implementation for SSL socket interface.
*/
-class TSSLSocket: public TSocket {
- public:
- ~TSSLSocket();
+class TSSLSocket : public TSocket {
+public:
+ ~TSSLSocket();
/**
* TTransport interface.
*/
- bool isOpen();
- bool peek();
- void open();
- void close();
+ bool isOpen();
+ bool peek();
+ void open();
+ void close();
uint32_t read(uint8_t* buf, uint32_t len);
- void write(const uint8_t* buf, uint32_t len);
- void flush();
- /**
- * Set whether to use client or server side SSL handshake protocol.
- *
- * @param flag Use server side handshake protocol if true.
- */
+ void write(const uint8_t* buf, uint32_t len);
+ void flush();
+ /**
+ * Set whether to use client or server side SSL handshake protocol.
+ *
+ * @param flag Use server side handshake protocol if true.
+ */
void server(bool flag) { server_ = flag; }
/**
* Determine whether the SSL socket is server or client mode.
@@ -89,9 +90,8 @@ class TSSLSocket: public TSocket {
*
* @param manager Instance of AccessManager
*/
- virtual void access(boost::shared_ptr<AccessManager> manager) {
- access_ = manager;
- }
+ virtual void access(boost::shared_ptr<AccessManager> manager) { access_ = manager; }
+
protected:
/**
* Constructor.
@@ -109,9 +109,7 @@ protected:
* @param host Remote host name
* @param port Remote port number
*/
- TSSLSocket(boost::shared_ptr<SSLContext> ctx,
- std::string host,
- int port);
+ TSSLSocket(boost::shared_ptr<SSLContext> ctx, std::string host, int port);
/**
* Authorize peer access after SSL handshake completes.
*/
@@ -132,7 +130,7 @@ protected:
* SSL socket factory. SSL sockets should be created via SSL factory.
*/
class TSSLSocketFactory {
- public:
+public:
/**
* Constructor/Destructor
*
@@ -150,14 +148,13 @@ class TSSLSocketFactory {
* @param socket An existing socket.
*/
virtual boost::shared_ptr<TSSLSocket> createSocket(THRIFT_SOCKET socket);
- /**
- * Create an instance of TSSLSocket.
- *
- * @param host Remote host to be connected to
- * @param port Remote port to be connected to
- */
- virtual boost::shared_ptr<TSSLSocket> createSocket(const std::string& host,
- int port);
+ /**
+ * Create an instance of TSSLSocket.
+ *
+ * @param host Remote host to be connected to
+ * @param port Remote port to be connected to
+ */
+ virtual boost::shared_ptr<TSSLSocket> createSocket(const std::string& host, int port);
/**
* Set ciphers to be used in SSL handshake process.
*
@@ -215,13 +212,12 @@ class TSSLSocketFactory {
*
* @param manager The AccessManager instance
*/
- virtual void access(boost::shared_ptr<AccessManager> manager) {
- access_ = manager;
- }
+ virtual void access(boost::shared_ptr<AccessManager> manager) { access_ = manager; }
static void setManualOpenSSLInitialization(bool manualOpenSSLInitialization) {
manualOpenSSLInitialization_ = manualOpenSSLInitialization;
}
- protected:
+
+protected:
boost::shared_ptr<SSLContext> ctx_;
/**
@@ -232,7 +228,8 @@ class TSSLSocketFactory {
* @param size Maximum length of password including NULL character
*/
virtual void getPassword(std::string& /* password */, int /* size */) {}
- private:
+
+private:
bool server_;
boost::shared_ptr<AccessManager> access_;
static concurrency::Mutex mutex_;
@@ -245,10 +242,10 @@ class TSSLSocketFactory {
/**
* SSL exception.
*/
-class TSSLException: public TTransportException {
- public:
- TSSLException(const std::string& message):
- TTransportException(TTransportException::INTERNAL_ERROR, message) {}
+class TSSLException : public TTransportException {
+public:
+ TSSLException(const std::string& message)
+ : TTransportException(TTransportException::INTERNAL_ERROR, message) {}
virtual const char* what() const throw() {
if (message_.empty()) {
@@ -263,12 +260,13 @@ class TSSLException: public TTransportException {
* Wrap OpenSSL SSL_CTX into a class.
*/
class SSLContext {
- public:
+public:
SSLContext(const SSLProtocol& protocol = SSLTLS);
virtual ~SSLContext();
SSL* createSSL();
SSL_CTX* get() { return ctx_; }
- private:
+
+private:
SSL_CTX* ctx_;
};
@@ -279,67 +277,73 @@ class SSLContext {
* object.
*/
class AccessManager {
- public:
+public:
enum Decision {
- DENY = -1, // deny access
- SKIP = 0, // cannot make decision, move on to next (if any)
- ALLOW = 1 // allow access
+ DENY = -1, // deny access
+ SKIP = 0, // cannot make decision, move on to next (if any)
+ ALLOW = 1 // allow access
};
- /**
- * Destructor
- */
- virtual ~AccessManager() {}
- /**
- * Determine whether the peer should be granted access or not. It's called
- * once after the SSL handshake completes successfully, before peer certificate
- * is examined.
- *
- * If a valid decision (ALLOW or DENY) is returned, the peer certificate is
- * not to be verified.
- *
- * @param sa Peer IP address
- * @return True if the peer is trusted, false otherwise
- */
- virtual Decision verify(const sockaddr_storage& /* sa */ ) throw() { return DENY; }
- /**
- * Determine whether the peer should be granted access or not. It's called
- * every time a DNS subjectAltName/common name is extracted from peer's
- * certificate.
- *
- * @param host Client mode: host name returned by TSocket::getHost()
- * Server mode: host name returned by TSocket::getPeerHost()
- * @param name SubjectAltName or common name extracted from peer certificate
- * @param size Length of name
- * @return True if the peer is trusted, false otherwise
- *
- * Note: The "name" parameter may be UTF8 encoded.
- */
- virtual Decision verify(const std::string& /* host */, const char* /* name */, int /* size */)
- throw() { return DENY; }
- /**
- * Determine whether the peer should be granted access or not. It's called
- * every time an IP subjectAltName is extracted from peer's certificate.
- *
- * @param sa Peer IP address retrieved from the underlying socket
- * @param data IP address extracted from certificate
- * @param size Length of the IP address
- * @return True if the peer is trusted, false otherwise
- */
- virtual Decision verify(const sockaddr_storage& /* sa */, const char* /* data */, int /* size */)
- throw() { return DENY; }
+ /**
+ * Destructor
+ */
+ virtual ~AccessManager() {}
+ /**
+ * Determine whether the peer should be granted access or not. It's called
+ * once after the SSL handshake completes successfully, before peer certificate
+ * is examined.
+ *
+ * If a valid decision (ALLOW or DENY) is returned, the peer certificate is
+ * not to be verified.
+ *
+ * @param sa Peer IP address
+ * @return True if the peer is trusted, false otherwise
+ */
+ virtual Decision verify(const sockaddr_storage& /* sa */) throw() { return DENY; }
+ /**
+ * Determine whether the peer should be granted access or not. It's called
+ * every time a DNS subjectAltName/common name is extracted from peer's
+ * certificate.
+ *
+ * @param host Client mode: host name returned by TSocket::getHost()
+ * Server mode: host name returned by TSocket::getPeerHost()
+ * @param name SubjectAltName or common name extracted from peer certificate
+ * @param size Length of name
+ * @return True if the peer is trusted, false otherwise
+ *
+ * Note: The "name" parameter may be UTF8 encoded.
+ */
+ virtual Decision verify(const std::string& /* host */,
+ const char* /* name */,
+ int /* size */) throw() {
+ return DENY;
+ }
+ /**
+ * Determine whether the peer should be granted access or not. It's called
+ * every time an IP subjectAltName is extracted from peer's certificate.
+ *
+ * @param sa Peer IP address retrieved from the underlying socket
+ * @param data IP address extracted from certificate
+ * @param size Length of the IP address
+ * @return True if the peer is trusted, false otherwise
+ */
+ virtual Decision verify(const sockaddr_storage& /* sa */,
+ const char* /* data */,
+ int /* size */) throw() {
+ return DENY;
+ }
};
typedef AccessManager::Decision Decision;
-class DefaultClientAccessManager: public AccessManager {
- public:
+class DefaultClientAccessManager : public AccessManager {
+public:
// AccessManager interface
Decision verify(const sockaddr_storage& sa) throw();
Decision verify(const std::string& host, const char* name, int size) throw();
Decision verify(const sockaddr_storage& sa, const char* data, int size) throw();
};
-
-
-}}}
+}
+}
+}
#endif
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TServerSocket.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TServerSocket.cpp b/lib/cpp/src/thrift/transport/TServerSocket.cpp
old mode 100755
new mode 100644
index 0ce1bce..e228dab
--- a/lib/cpp/src/thrift/transport/TServerSocket.cpp
+++ b/lib/cpp/src/thrift/transport/TServerSocket.cpp
@@ -52,76 +52,78 @@
#endif
#ifndef SOCKOPT_CAST_T
-# ifndef _WIN32
-# define SOCKOPT_CAST_T void
-# else
-# define SOCKOPT_CAST_T char
-# endif // _WIN32
+#ifndef _WIN32
+#define SOCKOPT_CAST_T void
+#else
+#define SOCKOPT_CAST_T char
+#endif // _WIN32
#endif
-template<class T>
+template <class T>
inline const SOCKOPT_CAST_T* const_cast_sockopt(const T* v) {
- return reinterpret_cast<const SOCKOPT_CAST_T*>(v);
+ return reinterpret_cast<const SOCKOPT_CAST_T*>(v);
}
-template<class T>
+template <class T>
inline SOCKOPT_CAST_T* cast_sockopt(T* v) {
- return reinterpret_cast<SOCKOPT_CAST_T*>(v);
+ return reinterpret_cast<SOCKOPT_CAST_T*>(v);
}
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
using namespace std;
using boost::shared_ptr;
-TServerSocket::TServerSocket(int port) :
- port_(port),
- serverSocket_(THRIFT_INVALID_SOCKET),
- acceptBacklog_(DEFAULT_BACKLOG),
- sendTimeout_(0),
- recvTimeout_(0),
- accTimeout_(-1),
- retryLimit_(0),
- retryDelay_(0),
- tcpSendBuffer_(0),
- tcpRecvBuffer_(0),
- keepAlive_(false),
- intSock1_(THRIFT_INVALID_SOCKET),
- intSock2_(THRIFT_INVALID_SOCKET)
-{}
-
-TServerSocket::TServerSocket(int port, int sendTimeout, int recvTimeout) :
- port_(port),
- serverSocket_(THRIFT_INVALID_SOCKET),
- acceptBacklog_(DEFAULT_BACKLOG),
- sendTimeout_(sendTimeout),
- recvTimeout_(recvTimeout),
- accTimeout_(-1),
- retryLimit_(0),
- retryDelay_(0),
- tcpSendBuffer_(0),
- tcpRecvBuffer_(0),
- keepAlive_(false),
- intSock1_(THRIFT_INVALID_SOCKET),
- intSock2_(THRIFT_INVALID_SOCKET)
-{}
-
-TServerSocket::TServerSocket(string path) :
- port_(0),
- path_(path),
- serverSocket_(THRIFT_INVALID_SOCKET),
- acceptBacklog_(DEFAULT_BACKLOG),
- sendTimeout_(0),
- recvTimeout_(0),
- accTimeout_(-1),
- retryLimit_(0),
- retryDelay_(0),
- tcpSendBuffer_(0),
- tcpRecvBuffer_(0),
- keepAlive_(false),
- intSock1_(THRIFT_INVALID_SOCKET),
- intSock2_(THRIFT_INVALID_SOCKET)
-{}
+TServerSocket::TServerSocket(int port)
+ : port_(port),
+ serverSocket_(THRIFT_INVALID_SOCKET),
+ acceptBacklog_(DEFAULT_BACKLOG),
+ sendTimeout_(0),
+ recvTimeout_(0),
+ accTimeout_(-1),
+ retryLimit_(0),
+ retryDelay_(0),
+ tcpSendBuffer_(0),
+ tcpRecvBuffer_(0),
+ keepAlive_(false),
+ intSock1_(THRIFT_INVALID_SOCKET),
+ intSock2_(THRIFT_INVALID_SOCKET) {
+}
+
+TServerSocket::TServerSocket(int port, int sendTimeout, int recvTimeout)
+ : port_(port),
+ serverSocket_(THRIFT_INVALID_SOCKET),
+ acceptBacklog_(DEFAULT_BACKLOG),
+ sendTimeout_(sendTimeout),
+ recvTimeout_(recvTimeout),
+ accTimeout_(-1),
+ retryLimit_(0),
+ retryDelay_(0),
+ tcpSendBuffer_(0),
+ tcpRecvBuffer_(0),
+ keepAlive_(false),
+ intSock1_(THRIFT_INVALID_SOCKET),
+ intSock2_(THRIFT_INVALID_SOCKET) {
+}
+
+TServerSocket::TServerSocket(string path)
+ : port_(0),
+ path_(path),
+ serverSocket_(THRIFT_INVALID_SOCKET),
+ acceptBacklog_(DEFAULT_BACKLOG),
+ sendTimeout_(0),
+ recvTimeout_(0),
+ accTimeout_(-1),
+ retryLimit_(0),
+ retryDelay_(0),
+ tcpSendBuffer_(0),
+ tcpRecvBuffer_(0),
+ keepAlive_(false),
+ intSock1_(THRIFT_INVALID_SOCKET),
+ intSock2_(THRIFT_INVALID_SOCKET) {
+}
TServerSocket::~TServerSocket() {
close();
@@ -161,7 +163,7 @@ void TServerSocket::setTcpRecvBuffer(int tcpRecvBuffer) {
void TServerSocket::listen() {
#ifdef _WIN32
- TWinsockSingleton::create();
+ TWinsockSingleton::create();
#endif // _WIN32
THRIFT_SOCKET sv[2];
if (-1 == THRIFT_SOCKETPAIR(AF_LOCAL, SOCK_STREAM, 0, sv)) {
@@ -187,7 +189,8 @@ void TServerSocket::listen() {
if (error) {
GlobalOutput.printf("getaddrinfo %d: %s", error, THRIFT_GAI_STRERROR(error));
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not resolve host for server socket.");
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not resolve host for server socket.");
}
// Pick the ipv6 address first since ipv4 addresses can be mapped
@@ -197,7 +200,7 @@ void TServerSocket::listen() {
break;
}
- if (! path_.empty()) {
+ if (!path_.empty()) {
serverSocket_ = socket(PF_UNIX, SOCK_STREAM, IPPROTO_IP);
} else {
serverSocket_ = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
@@ -207,72 +210,93 @@ void TServerSocket::listen() {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() socket() ", errno_copy);
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not create server socket.", errno_copy);
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not create server socket.",
+ errno_copy);
}
// Set THRIFT_NO_SOCKET_CACHING to prevent 2MSL delay on accept
int one = 1;
- if (-1 == setsockopt(serverSocket_, SOL_SOCKET, THRIFT_NO_SOCKET_CACHING,
- cast_sockopt(&one), sizeof(one))) {
- //ignore errors coming out of this setsockopt on Windows. This is because
- //SO_EXCLUSIVEADDRUSE requires admin privileges on WinXP, but we don't
- //want to force servers to be an admin.
+ if (-1 == setsockopt(serverSocket_,
+ SOL_SOCKET,
+ THRIFT_NO_SOCKET_CACHING,
+ cast_sockopt(&one),
+ sizeof(one))) {
+// ignore errors coming out of this setsockopt on Windows. This is because
+// SO_EXCLUSIVEADDRUSE requires admin privileges on WinXP, but we don't
+// want to force servers to be an admin.
#ifndef _WIN32
int errno_copy = THRIFT_GET_SOCKET_ERROR;
- GlobalOutput.perror("TServerSocket::listen() setsockopt() THRIFT_NO_SOCKET_CACHING ", errno_copy);
+ GlobalOutput.perror("TServerSocket::listen() setsockopt() THRIFT_NO_SOCKET_CACHING ",
+ errno_copy);
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not set THRIFT_NO_SOCKET_CACHING", errno_copy);
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not set THRIFT_NO_SOCKET_CACHING",
+ errno_copy);
#endif
}
// Set TCP buffer sizes
if (tcpSendBuffer_ > 0) {
- if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_SNDBUF,
- cast_sockopt(&tcpSendBuffer_), sizeof(tcpSendBuffer_))) {
+ if (-1 == setsockopt(serverSocket_,
+ SOL_SOCKET,
+ SO_SNDBUF,
+ cast_sockopt(&tcpSendBuffer_),
+ sizeof(tcpSendBuffer_))) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() setsockopt() SO_SNDBUF ", errno_copy);
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_SNDBUF", errno_copy);
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not set SO_SNDBUF",
+ errno_copy);
}
}
if (tcpRecvBuffer_ > 0) {
- if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_RCVBUF,
- cast_sockopt(&tcpRecvBuffer_), sizeof(tcpRecvBuffer_))) {
+ if (-1 == setsockopt(serverSocket_,
+ SOL_SOCKET,
+ SO_RCVBUF,
+ cast_sockopt(&tcpRecvBuffer_),
+ sizeof(tcpRecvBuffer_))) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() setsockopt() SO_RCVBUF ", errno_copy);
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_RCVBUF", errno_copy);
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not set SO_RCVBUF",
+ errno_copy);
}
}
- // Defer accept
- #ifdef TCP_DEFER_ACCEPT
+// Defer accept
+#ifdef TCP_DEFER_ACCEPT
if (path_.empty()) {
- if (-1 == setsockopt(serverSocket_, IPPROTO_TCP, TCP_DEFER_ACCEPT,
- &one, sizeof(one))) {
+ if (-1 == setsockopt(serverSocket_, IPPROTO_TCP, TCP_DEFER_ACCEPT, &one, sizeof(one))) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() setsockopt() TCP_DEFER_ACCEPT ", errno_copy);
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not set TCP_DEFER_ACCEPT", errno_copy);
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not set TCP_DEFER_ACCEPT",
+ errno_copy);
}
}
- #endif // #ifdef TCP_DEFER_ACCEPT
+#endif // #ifdef TCP_DEFER_ACCEPT
- #ifdef IPV6_V6ONLY
+#ifdef IPV6_V6ONLY
if (res->ai_family == AF_INET6 && path_.empty()) {
int zero = 0;
- if (-1 == setsockopt(serverSocket_, IPPROTO_IPV6, IPV6_V6ONLY,
- cast_sockopt(&zero), sizeof(zero))) {
+ if (-1 == setsockopt(serverSocket_,
+ IPPROTO_IPV6,
+ IPV6_V6ONLY,
+ cast_sockopt(&zero),
+ sizeof(zero))) {
GlobalOutput.perror("TServerSocket::listen() IPV6_V6ONLY ", THRIFT_GET_SOCKET_ERROR);
}
}
- #endif // #ifdef IPV6_V6ONLY
+#endif // #ifdef IPV6_V6ONLY
// Turn linger off, don't want to block on calls to close
struct linger ling = {0, 0};
- if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_LINGER,
- cast_sockopt(&ling), sizeof(ling))) {
+ if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_LINGER, cast_sockopt(&ling), sizeof(ling))) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() setsockopt() SO_LINGER ", errno_copy);
close();
@@ -282,12 +306,14 @@ void TServerSocket::listen() {
// Unix Sockets do not need that
if (path_.empty()) {
// TCP Nodelay, speed over bandwidth
- if (-1 == setsockopt(serverSocket_, IPPROTO_TCP, TCP_NODELAY,
- cast_sockopt(&one), sizeof(one))) {
+ if (-1
+ == setsockopt(serverSocket_, IPPROTO_TCP, TCP_NODELAY, cast_sockopt(&one), sizeof(one))) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() setsockopt() TCP_NODELAY ", errno_copy);
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not set TCP_NODELAY", errno_copy);
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not set TCP_NODELAY",
+ errno_copy);
}
}
@@ -310,7 +336,7 @@ void TServerSocket::listen() {
// always seem to work. The client can configure the retry variables.
int retries = 0;
- if (! path_.empty()) {
+ if (!path_.empty()) {
#ifndef _WIN32
@@ -328,14 +354,15 @@ void TServerSocket::listen() {
socklen_t structlen = static_cast<socklen_t>(sizeof(address));
do {
- if (0 == ::bind(serverSocket_, (struct sockaddr *) &address, structlen)) {
+ if (0 == ::bind(serverSocket_, (struct sockaddr*)&address, structlen)) {
break;
}
// use short circuit evaluation here to only sleep if we need to
} while ((retries++ < retryLimit_) && (THRIFT_SLEEP_SEC(retryDelay_) == 0));
#else
GlobalOutput.perror("TSocket::open() Unix Domain socket path not supported on windows", -99);
- throw TTransportException(TTransportException::NOT_OPEN, " Unix Domain socket path not supported");
+ throw TTransportException(TTransportException::NOT_OPEN,
+ " Unix Domain socket path not supported");
#endif
} else {
do {
@@ -356,16 +383,12 @@ void TServerSocket::listen() {
if (::getsockname(serverSocket_, &sa, &len) < 0) {
int errno_copy = errno;
GlobalOutput.perror("TServerSocket::getPort() getsockname() ", errno_copy);
- }
- else {
+ } else {
if (sa.sa_family == AF_INET6) {
- const struct sockaddr_in6*
- sin = reinterpret_cast<const struct sockaddr_in6 *>(&sa);
+ const struct sockaddr_in6* sin = reinterpret_cast<const struct sockaddr_in6*>(&sa);
port_ = ntohs(sin->sin6_port);
- }
- else {
- const struct sockaddr_in*
- sin = reinterpret_cast<const struct sockaddr_in *>(&sa);
+ } else {
+ const struct sockaddr_in* sin = reinterpret_cast<const struct sockaddr_in*>(&sa);
port_ = ntohs(sin->sin_port);
}
}
@@ -375,19 +398,20 @@ void TServerSocket::listen() {
// throw an error if we failed to bind properly
if (retries > retryLimit_) {
char errbuf[1024];
- if (! path_.empty()) {
+ if (!path_.empty()) {
sprintf(errbuf, "TServerSocket::listen() PATH %s", path_.c_str());
- }
- else {
+ } else {
sprintf(errbuf, "TServerSocket::listen() BIND %d", port_);
}
GlobalOutput(errbuf);
close();
- throw TTransportException(TTransportException::NOT_OPEN, "Could not bind",
+ throw TTransportException(TTransportException::NOT_OPEN,
+ "Could not bind",
THRIFT_GET_SOCKET_ERROR);
}
- if(listenCallback_) listenCallback_(serverSocket_);
+ if (listenCallback_)
+ listenCallback_(serverSocket_);
// Call listen
if (-1 == ::listen(serverSocket_, acceptBacklog_)) {
@@ -401,7 +425,7 @@ void TServerSocket::listen() {
}
int TServerSocket::getPort() {
- return port_;
+ return port_;
}
shared_ptr<TTransport> TServerSocket::acceptImpl() {
@@ -415,7 +439,7 @@ shared_ptr<TTransport> TServerSocket::acceptImpl() {
int numEintrs = 0;
while (true) {
- std::memset(fds, 0 , sizeof(fds));
+ std::memset(fds, 0, sizeof(fds));
fds[0].fd = serverSocket_;
fds[0].events = THRIFT_POLLIN;
if (intSock2_ != THRIFT_INVALID_SOCKET) {
@@ -440,11 +464,11 @@ shared_ptr<TTransport> TServerSocket::acceptImpl() {
throw TTransportException(TTransportException::UNKNOWN, "Unknown", errno_copy);
} else if (ret > 0) {
// Check for an interrupt signal
- if (intSock2_ != THRIFT_INVALID_SOCKET
- && (fds[1].revents & THRIFT_POLLIN)) {
+ if (intSock2_ != THRIFT_INVALID_SOCKET && (fds[1].revents & THRIFT_POLLIN)) {
int8_t buf;
if (-1 == recv(intSock2_, cast_sockopt(&buf), sizeof(int8_t), 0)) {
- GlobalOutput.perror("TServerSocket::acceptImpl() recv() interrupt ", THRIFT_GET_SOCKET_ERROR);
+ GlobalOutput.perror("TServerSocket::acceptImpl() recv() interrupt ",
+ THRIFT_GET_SOCKET_ERROR);
}
throw TTransportException(TTransportException::INTERRUPTED);
}
@@ -461,9 +485,8 @@ shared_ptr<TTransport> TServerSocket::acceptImpl() {
struct sockaddr_storage clientAddress;
int size = sizeof(clientAddress);
- THRIFT_SOCKET clientSocket = ::accept(serverSocket_,
- (struct sockaddr *) &clientAddress,
- (socklen_t *) &size);
+ THRIFT_SOCKET clientSocket
+ = ::accept(serverSocket_, (struct sockaddr*)&clientAddress, (socklen_t*)&size);
if (clientSocket == -1) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
@@ -476,13 +499,19 @@ shared_ptr<TTransport> TServerSocket::acceptImpl() {
if (flags == -1) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::acceptImpl() THRIFT_FCNTL() THRIFT_F_GETFL ", errno_copy);
- throw TTransportException(TTransportException::UNKNOWN, "THRIFT_FCNTL(THRIFT_F_GETFL)", errno_copy);
+ throw TTransportException(TTransportException::UNKNOWN,
+ "THRIFT_FCNTL(THRIFT_F_GETFL)",
+ errno_copy);
}
if (-1 == THRIFT_FCNTL(clientSocket, THRIFT_F_SETFL, flags & ~THRIFT_O_NONBLOCK)) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
- GlobalOutput.perror("TServerSocket::acceptImpl() THRIFT_FCNTL() THRIFT_F_SETFL ~THRIFT_O_NONBLOCK ", errno_copy);
- throw TTransportException(TTransportException::UNKNOWN, "THRIFT_FCNTL(THRIFT_F_SETFL)", errno_copy);
+ GlobalOutput
+ .perror("TServerSocket::acceptImpl() THRIFT_FCNTL() THRIFT_F_SETFL ~THRIFT_O_NONBLOCK ",
+ errno_copy);
+ throw TTransportException(TTransportException::UNKNOWN,
+ "THRIFT_FCNTL(THRIFT_F_SETFL)",
+ errno_copy);
}
shared_ptr<TSocket> client = createSocket(clientSocket);
@@ -495,9 +524,10 @@ shared_ptr<TTransport> TServerSocket::acceptImpl() {
if (keepAlive_) {
client->setKeepAlive(keepAlive_);
}
- client->setCachedAddress((sockaddr*) &clientAddress, size);
+ client->setCachedAddress((sockaddr*)&clientAddress, size);
- if(acceptCallback_) acceptCallback_(clientSocket);
+ if (acceptCallback_)
+ acceptCallback_(clientSocket);
return client;
}
@@ -521,7 +551,7 @@ void TServerSocket::close() {
::THRIFT_CLOSESOCKET(serverSocket_);
}
if (intSock1_ != THRIFT_INVALID_SOCKET) {
- ::THRIFT_CLOSESOCKET(intSock1_);
+ ::THRIFT_CLOSESOCKET(intSock1_);
}
if (intSock2_ != THRIFT_INVALID_SOCKET) {
::THRIFT_CLOSESOCKET(intSock2_);
@@ -530,5 +560,6 @@ void TServerSocket::close() {
intSock1_ = THRIFT_INVALID_SOCKET;
intSock2_ = THRIFT_INVALID_SOCKET;
}
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TServerSocket.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TServerSocket.h b/lib/cpp/src/thrift/transport/TServerSocket.h
index 56ec2b5..1533937 100644
--- a/lib/cpp/src/thrift/transport/TServerSocket.h
+++ b/lib/cpp/src/thrift/transport/TServerSocket.h
@@ -25,7 +25,9 @@
#include <thrift/cxxfunctional.h>
#include <boost/shared_ptr.hpp>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
class TSocket;
@@ -35,7 +37,7 @@ class TSocket;
*
*/
class TServerSocket : public TServerTransport {
- public:
+public:
typedef apache::thrift::stdcxx::function<void(THRIFT_SOCKET fd)> socket_func_t;
const static int DEFAULT_BACKLOG = 1024;
@@ -55,7 +57,7 @@ class TServerSocket : public TServerTransport {
void setRetryLimit(int retryLimit);
void setRetryDelay(int retryDelay);
- void setKeepAlive(bool keepAlive) {keepAlive_ = keepAlive;}
+ void setKeepAlive(bool keepAlive) { keepAlive_ = keepAlive; }
void setTcpSendBuffer(int tcpSendBuffer);
void setTcpRecvBuffer(int tcpRecvBuffer);
@@ -63,13 +65,13 @@ class TServerSocket : public TServerTransport {
// listenCallback gets called just before listen, and after all Thrift
// setsockopt calls have been made. If you have custom setsockopt
// things that need to happen on the listening socket, this is the place to do it.
- void setListenCallback(const socket_func_t &listenCallback) { listenCallback_ = listenCallback; }
+ void setListenCallback(const socket_func_t& listenCallback) { listenCallback_ = listenCallback; }
// acceptCallback gets called after each accept call, on the newly created socket.
// It is called after all Thrift setsockopt calls have been made. If you have
// custom setsockopt things that need to happen on the accepted
// socket, this is the place to do it.
- void setAcceptCallback(const socket_func_t &acceptCallback) { acceptCallback_ = acceptCallback; }
+ void setAcceptCallback(const socket_func_t& acceptCallback) { acceptCallback_ = acceptCallback; }
void listen();
void close();
@@ -77,11 +79,11 @@ class TServerSocket : public TServerTransport {
void interrupt();
int getPort();
- protected:
+protected:
boost::shared_ptr<TTransport> acceptImpl();
virtual boost::shared_ptr<TSocket> createSocket(THRIFT_SOCKET client);
- private:
+private:
int port_;
std::string path_;
THRIFT_SOCKET serverSocket_;
@@ -101,7 +103,8 @@ class TServerSocket : public TServerTransport {
socket_func_t listenCallback_;
socket_func_t acceptCallback_;
};
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
#endif // #ifndef _THRIFT_TRANSPORT_TSERVERSOCKET_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TServerTransport.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TServerTransport.h b/lib/cpp/src/thrift/transport/TServerTransport.h
index 2ddee0d..7c4a7c3 100644
--- a/lib/cpp/src/thrift/transport/TServerTransport.h
+++ b/lib/cpp/src/thrift/transport/TServerTransport.h
@@ -24,7 +24,9 @@
#include <thrift/transport/TTransportException.h>
#include <boost/shared_ptr.hpp>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
/**
* Server transport framework. A server needs to have some facility for
@@ -32,7 +34,7 @@ namespace apache { namespace thrift { namespace transport {
*
*/
class TServerTransport {
- public:
+public:
virtual ~TServerTransport() {}
/**
@@ -74,7 +76,7 @@ class TServerTransport {
*/
virtual void close() = 0;
- protected:
+protected:
TServerTransport() {}
/**
@@ -84,9 +86,9 @@ class TServerTransport {
* @throw TTransportException If an error occurs
*/
virtual boost::shared_ptr<TTransport> acceptImpl() = 0;
-
};
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
#endif // #ifndef _THRIFT_TRANSPORT_TSERVERTRANSPORT_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TShortReadTransport.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TShortReadTransport.h b/lib/cpp/src/thrift/transport/TShortReadTransport.h
index 8def354..f2ecae1 100644
--- a/lib/cpp/src/thrift/transport/TShortReadTransport.h
+++ b/lib/cpp/src/thrift/transport/TShortReadTransport.h
@@ -25,7 +25,10 @@
#include <thrift/transport/TTransport.h>
#include <thrift/transport/TVirtualTransport.h>
-namespace apache { namespace thrift { namespace transport { namespace test {
+namespace apache {
+namespace thrift {
+namespace transport {
+namespace test {
/**
* This class is only meant for testing. It wraps another transport.
@@ -34,64 +37,46 @@ namespace apache { namespace thrift { namespace transport { namespace test {
*
*/
class TShortReadTransport : public TVirtualTransport<TShortReadTransport> {
- public:
+public:
TShortReadTransport(boost::shared_ptr<TTransport> transport, double full_prob)
- : transport_(transport)
- , fullProb_(full_prob)
- {}
+ : transport_(transport), fullProb_(full_prob) {}
- bool isOpen() {
- return transport_->isOpen();
- }
+ bool isOpen() { return transport_->isOpen(); }
- bool peek() {
- return transport_->peek();
- }
+ bool peek() { return transport_->peek(); }
- void open() {
- transport_->open();
- }
+ void open() { transport_->open(); }
- void close() {
- transport_->close();
- }
+ void close() { transport_->close(); }
uint32_t read(uint8_t* buf, uint32_t len) {
if (len == 0) {
return 0;
}
- if (rand()/(double)RAND_MAX >= fullProb_) {
- len = 1 + rand()%len;
+ if (rand() / (double)RAND_MAX >= fullProb_) {
+ len = 1 + rand() % len;
}
return transport_->read(buf, len);
}
- void write(const uint8_t* buf, uint32_t len) {
- transport_->write(buf, len);
- }
+ void write(const uint8_t* buf, uint32_t len) { transport_->write(buf, len); }
- void flush() {
- transport_->flush();
- }
+ void flush() { transport_->flush(); }
- const uint8_t* borrow(uint8_t* buf, uint32_t* len) {
- return transport_->borrow(buf, len);
- }
+ const uint8_t* borrow(uint8_t* buf, uint32_t* len) { return transport_->borrow(buf, len); }
- void consume(uint32_t len) {
- return transport_->consume(len);
- }
+ void consume(uint32_t len) { return transport_->consume(len); }
- boost::shared_ptr<TTransport> getUnderlyingTransport() {
- return transport_;
- }
+ boost::shared_ptr<TTransport> getUnderlyingTransport() { return transport_; }
- protected:
+protected:
boost::shared_ptr<TTransport> transport_;
double fullProb_;
};
-
-}}}} // apache::thrift::transport::test
+}
+}
+}
+} // apache::thrift::transport::test
#endif // #ifndef _THRIFT_TRANSPORT_TSHORTREADTRANSPORT_H_
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TSimpleFileTransport.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TSimpleFileTransport.cpp b/lib/cpp/src/thrift/transport/TSimpleFileTransport.cpp
index 6bd716e..4b1399e 100644
--- a/lib/cpp/src/thrift/transport/TSimpleFileTransport.cpp
+++ b/lib/cpp/src/thrift/transport/TSimpleFileTransport.cpp
@@ -31,11 +31,12 @@
#include <io.h>
#endif
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
-TSimpleFileTransport::
-TSimpleFileTransport(const std::string& path, bool read, bool write)
- : TFDTransport(-1, TFDTransport::CLOSE_ON_DESTROY) {
+TSimpleFileTransport::TSimpleFileTransport(const std::string& path, bool read, bool write)
+ : TFDTransport(-1, TFDTransport::CLOSE_ON_DESTROY) {
int flags = 0;
if (read && write) {
flags = O_RDWR;
@@ -50,18 +51,17 @@ TSimpleFileTransport(const std::string& path, bool read, bool write)
flags |= O_CREAT | O_APPEND;
}
#ifndef _WIN32
- mode_t mode = S_IRUSR | S_IWUSR| S_IRGRP | S_IROTH;
+ mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
#else
int mode = _S_IREAD | _S_IWRITE;
#endif
- int fd = ::THRIFT_OPEN(path.c_str(),
- flags,
- mode);
+ int fd = ::THRIFT_OPEN(path.c_str(), flags, mode);
if (fd < 0) {
throw TTransportException("failed to open file for writing: " + path);
}
setFD(fd);
open();
}
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
http://git-wip-us.apache.org/repos/asf/thrift/blob/74260aa9/lib/cpp/src/thrift/transport/TSimpleFileTransport.h
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/TSimpleFileTransport.h b/lib/cpp/src/thrift/transport/TSimpleFileTransport.h
index 985a1d3..32e1897 100644
--- a/lib/cpp/src/thrift/transport/TSimpleFileTransport.h
+++ b/lib/cpp/src/thrift/transport/TSimpleFileTransport.h
@@ -22,7 +22,9 @@
#include <thrift/transport/TFDTransport.h>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
/**
* Dead-simple wrapper around a file.
@@ -30,12 +32,11 @@ namespace apache { namespace thrift { namespace transport {
* Writeable files are opened with O_CREAT and O_APPEND
*/
class TSimpleFileTransport : public TFDTransport {
- public:
- TSimpleFileTransport(const std::string& path,
- bool read = true,
- bool write = false);
+public:
+ TSimpleFileTransport(const std::string& path, bool read = true, bool write = false);
};
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
#endif // _THRIFT_TRANSPORT_TSIMPLEFILETRANSPORT_H_