You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2009/03/26 07:23:59 UTC
svn commit: r758533 - in /incubator/thrift/trunk/lib/cpp: Makefile.am
src/transport/TSimpleFileTransport.cpp src/transport/TSimpleFileTransport.h
Author: dreiss
Date: Thu Mar 26 06:23:57 2009
New Revision: 758533
URL: http://svn.apache.org/viewvc?rev=758533&view=rev
Log:
THRIFT-255. cpp: Add TSimpleFileTransport, a wrapper around TFDTransport
Added:
incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.cpp
incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.h
Modified:
incubator/thrift/trunk/lib/cpp/Makefile.am
Modified: incubator/thrift/trunk/lib/cpp/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/Makefile.am?rev=758533&r1=758532&r2=758533&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/Makefile.am (original)
+++ incubator/thrift/trunk/lib/cpp/Makefile.am Thu Mar 26 06:23:57 2009
@@ -36,6 +36,7 @@
src/transport/TTransportException.cpp \
src/transport/TFDTransport.cpp \
src/transport/TFileTransport.cpp \
+ src/transport/TSimpleFileTransport.cpp \
src/transport/THttpClient.cpp \
src/transport/TSocket.cpp \
src/transport/TSocketPool.cpp \
@@ -94,6 +95,7 @@
include_transport_HEADERS = \
src/transport/TFDTransport.h \
src/transport/TFileTransport.h \
+ src/transport/TSimpleFileTransport.h \
src/transport/TServerSocket.h \
src/transport/TServerTransport.h \
src/transport/THttpClient.h \
Added: incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.cpp?rev=758533&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.cpp (added)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.cpp Thu Mar 26 06:23:57 2009
@@ -0,0 +1,41 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#include "TSimpleFileTransport.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+namespace apache { namespace thrift { namespace transport {
+
+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;
+ } else if (read) {
+ flags = O_RDONLY;
+ } else if (write) {
+ flags = O_WRONLY;
+ } else {
+ throw TTransportException("Neither READ nor WRITE specified");
+ }
+ if (write) {
+ flags |= O_CREAT | O_APPEND;
+ }
+ int fd = ::open(path.c_str(),
+ flags,
+ S_IRUSR | S_IWUSR| S_IRGRP | S_IROTH);
+ if (fd < 0) {
+ throw TTransportException("failed to open file for writing: " + path);
+ }
+ setFD(fd);
+ open();
+}
+
+}}} // apache::thrift::transport
Added: incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.h?rev=758533&view=auto
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.h (added)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TSimpleFileTransport.h Thu Mar 26 06:23:57 2009
@@ -0,0 +1,28 @@
+// Copyright (c) 2006- Facebook
+// Distributed under the Thrift Software License
+//
+// See accompanying file LICENSE or visit the Thrift site at:
+// http://developers.facebook.com/thrift/
+
+#ifndef _THRIFT_TRANSPORT_TSIMPLEFILETRANSPORT_H_
+#define _THRIFT_TRANSPORT_TSIMPLEFILETRANSPORT_H_ 1
+
+#include "TFDTransport.h"
+
+namespace apache { namespace thrift { namespace transport {
+
+/**
+ * Dead-simple wrapper around a file.
+ *
+ * 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);
+};
+
+}}} // apache::thrift::transport
+
+#endif // _THRIFT_TRANSPORT_TSIMPLEFILETRANSPORT_H_