Permalink
Browse files

Merge commit 'origin/master' into new_erl

  • Loading branch information...
2 parents 27c1c35 + c347647 commit d9971339df209014057026fc3b11a3a846800f18 eugene letuchy committed Mar 6, 2008
@@ -1353,18 +1353,20 @@ void t_cpp_generator::generate_service_interface(t_service* tservice) {
f_header_ <<
indent() << "virtual ~" << service_name_ << "If() {}" << endl;
- f_header_ <<
- indent() << "static void getStaticLimitedReflection" <<
- "(facebook::thrift::reflection::limited::Service & _return);" << endl;
- // TODO(dreiss): Uncomment and test this if we decide we need
- // a virtual function with this effect.
- //f_header_ <<
- // indent() << "virtual void getVirtualLimitedReflection" <<
- // "(facebook::thrift::reflection::limited::Service & _return) ";
- //scope_up(f_header_);
- //f_header_ <<
- // indent() << "getStaticLimitedReflection(_return);" << endl;
- //scope_down(f_header_);
+ if (gen_reflection_limited_) {
+ f_header_ <<
+ indent() << "static void getStaticLimitedReflection" <<
+ "(facebook::thrift::reflection::limited::Service & _return);" << endl;
+ // TODO(dreiss): Uncomment and test this if we decide we need
+ // a virtual function with this effect.
+ //f_header_ <<
+ // indent() << "virtual void getVirtualLimitedReflection" <<
+ // "(facebook::thrift::reflection::limited::Service & _return) ";
+ //scope_up(f_header_);
+ //f_header_ <<
+ // indent() << "getStaticLimitedReflection(_return);" << endl;
+ //scope_down(f_header_);
+ }
vector<t_function*> functions = tservice->get_functions();
vector<t_function*>::iterator f_iter;
@@ -1403,16 +1405,14 @@ void t_cpp_generator::generate_service_null(t_service* tservice) {
if (returntype->is_void()) {
f_header_ <<
indent() << "return;" << endl;
+ } else if (is_complex_type(returntype)) {
+ f_header_ <<
+ indent() << "return;" << endl;
} else {
- if (is_complex_type(returntype)) {
- f_header_ <<
- indent() << "return;" << endl;
- } else {
- t_field returnfield(returntype, "_return");
- f_header_ <<
- indent() << declare_field(&returnfield, true) << endl <<
- indent() << "return _return;" << endl;
- }
+ t_field returnfield(returntype, "_return");
+ f_header_ <<
+ indent() << declare_field(&returnfield, true) << endl <<
+ indent() << "return _return;" << endl;
}
indent_down();
f_header_ <<
@@ -2342,5 +2342,5 @@ void t_java_generator::generate_java_doc(ofstream &out,
THRIFT_REGISTER_GENERATOR(java, "Java",
" beans: Generate bean-style output files.\n"
-" hashcode: Generate quality hashCode methods.\n"
+" hashcode: Generate quality hashCode methods.\n"
);
View
@@ -10,7 +10,7 @@ AC_ARG_VAR([PY_PREFIX], [Prefix for installing Python modules.
(Normal --prefix is ignored for Python because
Python has different conventions.)
Default = "/usr"])
-AS_IF([test "x$PY_PREFIX" == x], [PY_PREFIX="/usr"])
+AS_IF([test "x$PY_PREFIX" = x], [PY_PREFIX="/usr"])
AM_PATH_PYTHON(2.4,, :)
@@ -51,6 +51,13 @@ fi
AM_CONDITIONAL([ENABLE_JAVA],
[test -n "$ANT" -a -n "$JAVA" -a -n "$JAVAC"])
+AX_THRIFT_LIB(erlang, [Erlang], yes)
+if test "$with_erlang" = "yes"; then
+ AC_PATH_PROG([ERLC], [erlc])
+fi
+
+AM_CONDITIONAL(ENABLE_ERLANG, [test -n "$ERLC"])
+
AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE
View
@@ -10,6 +10,10 @@ if ENABLE_JAVA
SUBDIRS += java
endif
+if ENABLE_ERLANG
+SUBDIRS += erl
+endif
+
EXTRA_DIST = \
cocoa \
erl \
@@ -37,13 +37,16 @@ namespace facebook { namespace thrift { namespace concurrency {
class Util {
static const int64_t NS_PER_S = 1000000000LL;
+ static const int64_t US_PER_S = 1000000LL;
static const int64_t MS_PER_S = 1000LL;
- static const int64_t NS_PER_MS = 1000000LL;
+
+ static const int64_t NS_PER_MS = NS_PER_S / MS_PER_S;
+ static const int64_t US_PER_MS = US_PER_S / MS_PER_S;
public:
/**
- * Converts timespec to milliseconds
+ * Converts millisecond timestamp into a timespec struct
*
* @param struct timespec& result
* @param time or duration in milliseconds
@@ -53,37 +56,52 @@ class Util {
result.tv_nsec = (value % MS_PER_S) * NS_PER_MS; // ms to ns
}
+ static void toTimeval(struct timeval& result, int64_t value) {
+ result.tv_sec = value / MS_PER_S; // ms to s
+ result.tv_usec = (value % MS_PER_S) * US_PER_MS; // ms to us
+ }
+
/**
- * Converts timespec to milliseconds
+ * Converts struct timespec to milliseconds
*/
static const void toMilliseconds(int64_t& result, const struct timespec& value) {
- result =
- (value.tv_sec * MS_PER_S) +
- (value.tv_nsec / NS_PER_MS) +
- (value.tv_nsec % NS_PER_MS >= 500000 ? 1 : 0);
+ result = (value.tv_sec * MS_PER_S) + (value.tv_nsec / NS_PER_MS);
+ // round up -- int64_t cast is to avoid a compiler error for some GCCs
+ if (int64_t(value.tv_nsec) % NS_PER_MS >= (NS_PER_MS / 2)) {
+ ++result;
+ }
+ }
+
+ /**
+ * Converts struct timeval to milliseconds
+ */
+ static const void toMilliseconds(int64_t& result, const struct timeval& value) {
+ result = (value.tv_sec * MS_PER_S) + (value.tv_usec / US_PER_MS);
+ // round up -- int64_t cast is to avoid a compiler error for some GCCs
+ if (int64_t(value.tv_usec) % US_PER_MS >= (US_PER_MS / 2)) {
+ ++result;
+ }
}
/**
* Get current time as milliseconds from epoch
*/
static const int64_t currentTime() {
+ int64_t result;
+
#if defined(HAVE_CLOCK_GETTIME)
struct timespec now;
int ret = clock_gettime(CLOCK_REALTIME, &now);
assert(ret == 0);
- return
- (now.tv_sec * MS_PER_S) +
- (now.tv_nsec / NS_PER_MS) +
- (now.tv_nsec % NS_PER_MS >= 500000 ? 1 : 0) ;
+ toMilliseconds(result, now);
#elif defined(HAVE_GETTIMEOFDAY)
struct timeval now;
int ret = gettimeofday(&now, NULL);
assert(ret == 0);
- return
- (((int64_t)now.tv_sec) * MS_PER_S) +
- (now.tv_usec / MS_PER_S) +
- (now.tv_usec % MS_PER_S >= 500 ? 1 : 0);
+ toMilliseconds(result, now);
#endif // defined(HAVE_GETTIMEDAY)
+
+ return result;
}
};
@@ -40,11 +40,11 @@ class TConnection::Task: public Runnable {
}
}
} catch (TTransportException& ttx) {
- cerr << "TThreadedServer client died: " << ttx.what() << endl;
+ cerr << "TNonblockingServer client died: " << ttx.what() << endl;
} catch (TException& x) {
- cerr << "TThreadedServer exception: " << x.what() << endl;
+ cerr << "TNonblockingServer exception: " << x.what() << endl;
} catch (...) {
- cerr << "TThreadedServer uncaught exception." << endl;
+ cerr << "TNonblockingServer uncaught exception." << endl;
}
// Signal completion back to the libevent thread via a socketpair
@@ -355,7 +355,7 @@ void TConnection::transition() {
// Register read event
setRead();
-
+
// Try to work the socket right away
// workSocket();
@@ -495,7 +495,8 @@ void TNonblockingServer::returnConnection(TConnection* connection) {
}
/**
- * Server socket had something happen
+ * Server socket had something happen. We accept all waiting client
+ * connections on fd and assign TConnection objects to handle those requests.
*/
void TNonblockingServer::handleEvent(int fd, short which) {
// Make sure that libevent didn't fuck up the socket handles
@@ -297,30 +297,44 @@ uint32_t TMemoryBuffer::readAppendToString(std::string& str, uint32_t len) {
return give;
}
-void TMemoryBuffer::write(const uint8_t* buf, uint32_t len) {
+void TMemoryBuffer::ensureCanWrite(uint32_t len) {
// Check available space
uint32_t avail = bufferSize_ - wPos_;
+ if (len <= avail) {
+ return;
+ }
- // Grow the buffer
- if (len > avail) {
- if (!owner_) {
- throw TTransportException("Insufficient space in external MemoryBuffer");
- }
- while (len > avail) {
- bufferSize_ *= 2;
- avail = bufferSize_ - wPos_;
- }
- buffer_ = (uint8_t*)std::realloc(buffer_, bufferSize_);
- if (buffer_ == NULL) {
- throw TTransportException("Out of memory.");
- }
+ if (!owner_) {
+ throw TTransportException("Insufficient space in external MemoryBuffer");
+ }
+
+ // Grow the buffer as necessary
+ while (len > avail) {
+ bufferSize_ *= 2;
+ avail = bufferSize_ - wPos_;
+ }
+ buffer_ = (uint8_t*)std::realloc(buffer_, bufferSize_);
+ if (buffer_ == NULL) {
+ throw TTransportException("Out of memory.");
}
+}
+
+void TMemoryBuffer::write(const uint8_t* buf, uint32_t len) {
+ ensureCanWrite(len);
// Copy into the buffer and increment wPos_
memcpy(buffer_ + wPos_, buf, len);
wPos_ += len;
}
+void TMemoryBuffer::wroteBytes(uint32_t len) {
+ uint32_t avail = bufferSize_ - wPos_;
+ if (len > avail) {
+ throw TTransportException("Client wrote more bytes than size of buffer.");
+ }
+ wPos_ += len;
+}
+
const uint8_t* TMemoryBuffer::borrow(uint8_t* buf, uint32_t* len) {
if (wPos_-rPos_ >= *len) {
*len = wPos_-rPos_;
@@ -315,6 +315,9 @@ class TMemoryBuffer : public TTransport {
rPos_ = 0;
}
+ // make sure there's at least 'len' bytes available for writing
+ void ensureCanWrite(uint32_t len);
+
public:
static const uint32_t defaultSize = 1024;
@@ -480,7 +483,7 @@ class TMemoryBuffer : public TTransport {
void write(const uint8_t* buf, uint32_t len);
- uint32_t available() {
+ uint32_t available() const {
return wPos_ - rPos_;
}
@@ -496,6 +499,20 @@ class TMemoryBuffer : public TTransport {
swap(owner_, that.owner_);
}
+ // Returns a pointer to where the client can write data to append to
+ // the TMemoryBuffer, and ensures the buffer is big enough to accomodate a
+ // write of the provided length. The returned pointer is very convenient for
+ // passing to read(), recv(), or similar. You must call wroteBytes() as soon
+ // as data is written or the buffer will not be aware that data has changed.
+ uint8_t* getWritePtr(uint32_t len) {
+ ensureCanWrite(len);
+ return buffer_ + wPos_;
+ }
+
+ // Informs the buffer that the client has written 'len' bytes into storage
+ // that had been provided by getWritePtr().
+ void wroteBytes(uint32_t len);
+
private:
// Data buffer
uint8_t* buffer_;
View
@@ -25,8 +25,8 @@ INSTALL_DST = $(ERLANG_OTP)/lib/$(APP_NAME)-$(VSN)
# ----------------------------------------------------
-MODULES = $(shell find -name \*.erl | sed s:^\\./:: | sed s/\\.erl//)
-MODULES_STRING_LIST = $(shell find -name \*.erl | sed s:^\\./:\": | sed s/\\.erl/\",/)
+MODULES = $(shell find . -name \*.erl | sed s:^\\./:: | sed s/\\.erl//)
+MODULES_STRING_LIST = $(shell find . -name \*.erl | sed s:^\\./:\": | sed s/\\.erl/\",/)
HRL_FILES=
INTERNAL_HRL_FILES= $(APP_NAME).hrl
@@ -391,7 +391,7 @@ void binary_deserialize(int8_t thrift_typeID, PHPInputTransport& transport, zval
RETURN_NULL();
}
TSRMLS_FETCH();
- zval* spec = zend_read_static_property(zend_get_class_entry(return_value TSRMLS_CC), "_TSPEC", 6, false);
+ zval* spec = zend_read_static_property(zend_get_class_entry(return_value TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC);
if (Z_TYPE_P(spec) != IS_ARRAY) {
char errbuf[128];
snprintf(errbuf, 128, "spec for %s is wrong type: %d\n", structType, Z_TYPE_P(spec));
@@ -681,7 +681,7 @@ void binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval*
return;
case T_STRUCT: {
TSRMLS_FETCH();
- zval* spec = zend_read_static_property(zend_get_class_entry(*value TSRMLS_CC), "_TSPEC", 6, false);
+ zval* spec = zend_read_static_property(zend_get_class_entry(*value TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC);
binary_serialize_spec(*value, transport, Z_ARRVAL_P(spec));
} return;
case T_BOOL:
@@ -870,7 +870,7 @@ PHP_FUNCTION(thrift_protocol_write_binary) {
transport.writeI32(seqID);
}
- zval* spec = zend_read_static_property(zend_get_class_entry(request_struct TSRMLS_CC), "_TSPEC", 6, false);
+ zval* spec = zend_read_static_property(zend_get_class_entry(request_struct TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC);
binary_serialize_spec(request_struct, transport, Z_ARRVAL_P(spec));
} catch (const PHPExceptionWrapper& ex) {
zend_throw_exception_object(ex TSRMLS_CC);
@@ -937,13 +937,13 @@ PHP_FUNCTION(thrift_protocol_read_binary) {
zval* ex;
MAKE_STD_ZVAL(ex);
createObject("TApplicationException", ex);
- zval* spec = zend_read_static_property(zend_get_class_entry(ex TSRMLS_CC), "_TSPEC", 6, false);
+ zval* spec = zend_read_static_property(zend_get_class_entry(ex TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC);
binary_deserialize_spec(ex, transport, Z_ARRVAL_P(spec));
throw PHPExceptionWrapper(ex);
}
createObject(obj_typename, return_value);
- zval* spec = zend_read_static_property(zend_get_class_entry(return_value TSRMLS_CC), "_TSPEC", 6, false);
+ zval* spec = zend_read_static_property(zend_get_class_entry(return_value TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC);
binary_deserialize_spec(return_value, transport, Z_ARRVAL_P(spec));
} catch (const PHPExceptionWrapper& ex) {
zend_throw_exception_object(ex TSRMLS_CC);
@@ -0,0 +1,8 @@
+PHP_ARG_ENABLE(thrift_protocol, whether to enable the thrift_protocol extension,
+[ --enable-thrift_protocol Enable the fbthrift_protocol extension])
+
+if test "$PHP_THRIFT_PROTOCOL" != "no"; then
+ PHP_REQUIRE_CXX()
+ PHP_NEW_EXTENSION(thrift_protocol, php_thrift_protocol.cpp, $ext_shared)
+fi
+
Oops, something went wrong.

0 comments on commit d997133

Please sign in to comment.