LDLIBS += -lopensrf
CFLAGS += -D_LARGEFILE64_SOURCE -DOSRF_LOG_PARAMS
-all: osrf_math.so osrf_dbmath.so osrf_version.so
+all: osrf_math.so osrf_dbmath.so osrf_version.so timejson
+timejson.o: timejson.c
osrf_math.o: osrf_math.c
osrf_dbmath.o: osrf_dbmath.c
osrf_version.o: osrf_version.c
+timejson: timejson.o
+ $(CC) -shared -W1 $(LDLIBS) $(LDFLAGS) timejson.o -o $(TMPDIR)/timejson
+
osrf_math.so: osrf_math.o
$(CC) -shared -W1 $(LDLIBS) $(LDFLAGS) osrf_math.o -o $(TMPDIR)/osrf_math.so
--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <malloc.h>
+#include "opensrf/utils.h"
+#include "opensrf/osrf_json.h"
+
+struct timeval diff_timeval( const struct timeval * begin,
+ const struct timeval * end );
+
+static const char sample_json[] =
+ "{\"menu\": {\"id\": \"file\", \"value\": \"File\","
+ "\"popup\": { \"menuitem\": [ {\"value\": \"New\", "
+ "\"onclick\": \"CreateNewDoc()\"},"
+ "{\"value\": \"Open\", \"onclick\": \"OpenDoc()\"}, "
+ "{\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}]}}}";
+
+int main( void ) {
+ int rc = 0;
+
+ struct timezone tz = { 240, 1 };
+ struct timeval begin_timeval;
+ struct timeval end_timeval;
+
+ gettimeofday( &begin_timeval, &tz );
+
+ long i;
+ jsonObject * pObj = NULL;
+
+ for( i = 10000000; i; --i )
+ {
+// pObj = jsonParseString( sample_json );
+ pObj = jsonNewObject( NULL );
+ jsonObject * p1 = jsonNewObject( NULL );
+ jsonObject * p2 = jsonNewObject( NULL );
+ jsonObjectFree( p1 );
+ jsonObjectFree( p2 );
+ jsonObjectFree( pObj );
+ }
+
+ jsonObjectFreeUnused();
+
+ gettimeofday( &end_timeval, &tz );
+
+ struct timeval elapsed = diff_timeval( &begin_timeval, &end_timeval );
+
+ printf( "Elapsed time: %ld seconds, %ld microseconds\n",
+ (long) elapsed.tv_sec, (long) elapsed.tv_usec );
+
+ struct rlimit rlim;
+ if( getrlimit( RLIMIT_DATA, &rlim ) )
+ printf( "Error calling getrlimit\n" );
+ else
+ printf( "Address space: %lu\n", (unsigned long) rlim.rlim_cur );
+
+ malloc_stats();
+
+ return rc;
+}
+
+struct timeval diff_timeval( const struct timeval * begin, const struct timeval * end )
+{
+ struct timeval diff;
+
+ diff.tv_sec = end->tv_sec - begin->tv_sec;
+ diff.tv_usec = end->tv_usec - begin->tv_usec;
+
+ if( diff.tv_usec < 0 )
+ {
+ diff.tv_usec += 1000000;
+ --diff.tv_sec;
+ }
+
+ return diff;
+
+}
int sock_fd;
struct sockaddr_un server_addr;
+ if(strlen(path) > sizeof(server_addr.sun_path) - 1)
+ {
+ osrfLogWarning( OSRF_LOG_MARK, "socket_open_unix_server(): path too long: %s",
+ path );
+ return -1;
+ }
+
errno = 0;
sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
if(sock_fd < 0){
int sock_fd, len;
struct sockaddr_un usock;
+ if(strlen(sock_path) > sizeof(usock.sun_path) - 1)
+ {
+ osrfLogWarning( OSRF_LOG_MARK, "socket_open_unix_client(): path too long: %s",
+ sock_path );
+ return -1;
+ }
+
errno = 0;
if( (sock_fd = socket( AF_UNIX, SOCK_STREAM, 0 )) < 0 ) {
osrfLogWarning( OSRF_LOG_MARK, "socket_open_unix_client(): Cannot create UNIX socket: %s", strerror( errno ) );
osrfLogInternal( OSRF_LOG_MARK, "%ld : Received data at %f\n", (long) getpid(), get_timestamp_millis());
while( (read_bytes = recv(sock_fd, buf, RBUFSIZE-1, 0) ) > 0 ) {
+ buf[read_bytes] = '\0';
osrfLogInternal( OSRF_LOG_MARK, "Socket %d Read %d bytes and data: %s", sock_fd, read_bytes, buf);
if(mgr->data_received)
mgr->data_received(mgr->blob, mgr, sock_fd, buf, node->parent_id);