Repository: geode-native Updated Branches: refs/heads/develop ac76aaced -> c38580a54
GEODE-2446: Remove cclient directory. This closes #4. Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/c38580a5 Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/c38580a5 Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/c38580a5 Branch: refs/heads/develop Commit: c38580a543221c2558a64cbaafc2a871885a4ac9 Parents: ac76aac Author: Sarge <[email protected]> Authored: Fri Feb 10 15:25:59 2017 -0800 Committer: Jacob Barrett <[email protected]> Committed: Mon Feb 13 16:52:55 2017 -0800 ---------------------------------------------------------------------- src/cclient/README | 34 -- src/cclient/sample/runit.sh | 33 -- src/cclient/sample/sample.c | 102 ---- src/cclient/sample/sampleserver.xml | 33 -- src/cclient/src/data_io.c | 329 ------------- src/cclient/src/data_io.h | 90 ---- src/cclient/src/gf_client.c | 822 ------------------------------- src/cclient/src/gf_client.h | 105 ---- 8 files changed, 1548 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/README ---------------------------------------------------------------------- diff --git a/src/cclient/README b/src/cclient/README deleted file mode 100644 index 388e268..0000000 --- a/src/cclient/README +++ /dev/null @@ -1,34 +0,0 @@ -Operating instructions: -This is first cut of C client for Gemfire cache. -Source code is in src directory. There is a sample programe in sample -directory, which demonstrates basic usage of the library. There is a -Makefile provided which builds the library, as well as sample program. -To run the sample program, execute runit.sh in sample directory. -Befure executing runit.sh GEMFIRE and GFCCLIENT environment variables -have to be set. GEMFIRE should contain path to Gemfire installation -and GFCCLIENT should contain path to C client dist library (which is -created while building using Makefile). - -NOTES: -1. gf_connect function returns a CONTEXT pointer which should be passed - while doing any operation. -2. A CONTEXT pointer should not be used to perform multiple operations - simultaneously -3. A program can maintain a pool of CONTEXT pointers, and any thread can - borrow the pointer and return it when done. -4. There is a gf_ping function in the API. Idle timeout at the server is - 60 seconds certain interval, otherwise it closes the socket. A program - should call gf_ping function periodically in a separate thread. -2. gf_disconnect frees up the CONTEXT pointer - - -Troubleshooting: -Write now, client does not have any logging. For troubleshooting, -server logs have to be analysed. To enable all logs in the server, -'log-level=all' has to be passed as command line arguments while -starting the server. In samples directory, 'runit.sh' contains the -command for starting the server with all logging enabled. - -Contact information: -Ankur Srivastava <[email protected]> -Vishal Rao <[email protected]> http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/sample/runit.sh ---------------------------------------------------------------------- diff --git a/src/cclient/sample/runit.sh b/src/cclient/sample/runit.sh deleted file mode 100755 index 3c315ae..0000000 --- a/src/cclient/sample/runit.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -if [ -z ${GFCCLIENT:-} ]; then - echo GFCCLIENT is not set. - exit 1 -fi -if [ -z ${GEMFIRE:-} ]; then - echo GEMFIRE is not set. - exit 1 -fi - - -export LD_LIBRARY_PATH=$GFCCLIENT:$LD_LIBRARY_PATH -$GEMFIRE/bin/cacheserver start cache-xml-file=sampleserver.xml log-level=all -./sample -$GEMFIRE/bin/cacheserver stop - http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/sample/sample.c ---------------------------------------------------------------------- diff --git a/src/cclient/sample/sample.c b/src/cclient/sample/sample.c deleted file mode 100644 index 06dc62b..0000000 --- a/src/cclient/sample/sample.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <gf_client.h> -#include <stdio.h> - -void printByteArray(int8_t* arr, int32_t len) -{ - int32_t i = 0; - for(i = 0; i < len; i++) - { - printf("%d", arr[i]); - } -} - - -int main(int argc, char** argv) -{ - int resultcode = NO_ERROR; - char* key = "key"; - int8_t data[] = {1,2,3,4}; - int8_t returnData[4]; - CONTEXT* context = gf_connect("localhost", "40404", &resultcode); - if(resultcode == NO_ERROR) - { - printf("Connection successful.\n"); - if(context != NULL) { - resultcode = NO_ERROR; - printf("Sending ping message... "); - gf_ping(context, &resultcode); - if(resultcode == NO_ERROR) - { - printf("successful.\n"); - } else { - printf("failed. Error code: %d\n", resultcode); - } - - resultcode = NO_ERROR; - printf("Sending put with key=%s, and value=", key); - printByteArray(data, 4); - printf("... "); - gf_put(context, key, data, 4, &resultcode); - if(resultcode == NO_ERROR) - { - printf("successful.\n"); - } else { - printf("failed. Error code: %d\n", resultcode); - } - - resultcode = NO_ERROR; - printf("Sending get message with key=%s... ", key); - gf_get(context, "key",returnData, 1024, &resultcode); - if(resultcode == NO_ERROR) - { - printf("successful. got '"); - printByteArray(returnData, 4); - printf("'.\n"); - } else { - printf("failed. Error code: %d\n", resultcode); - } - - resultcode = NO_ERROR; - printf("Sending destroy with key=%s... ", key); - gf_destroy(context, "key", &resultcode); - if(resultcode == NO_ERROR) - { - printf("successful.\n"); - } else { - printf("failed. Error code: %d\n", resultcode); - } - - resultcode = NO_ERROR; - printf("disconnecting... "); - gf_disconnect(context, &resultcode); - if(resultcode == NO_ERROR) - { - printf("successful.\n"); - } else { - printf("failed. Error code: %d\n", resultcode); - } - } - } else { - printf("Connection failure. Error Code: %d\n", resultcode); - } - - return 0; -} - http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/sample/sampleserver.xml ---------------------------------------------------------------------- diff --git a/src/cclient/sample/sampleserver.xml b/src/cclient/sample/sampleserver.xml deleted file mode 100644 index 9a26b14..0000000 --- a/src/cclient/sample/sampleserver.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0"?> - -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - - -<!-- serverBasicOperations.xml - Configures a server to for clients at port 40404. ---> - -<cache xmlns="http://geode.apache.org/schema/cache" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" - version="1.0"> - <cache-server port="40404"/> - <region name="ROOT-REGION"> - <region-attributes scope="distributed-no-ack" data-policy="replicate"/> - </region> -</cache> http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/src/data_io.c ---------------------------------------------------------------------- diff --git a/src/cclient/src/data_io.c b/src/cclient/src/data_io.c deleted file mode 100644 index ae59db5..0000000 --- a/src/cclient/src/data_io.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "data_io.h" -#include <stdio.h> -/** - * Write an unsigned byte to the <code>DataOutput</code>. - * - * @param value the unsigned byte to be written - */ -inline void writeUnsigned(Buffer* buf, uint8_t value) -{ - ensureCapacity(buf,1); - writeNoCheck(buf, value); -} - -/** - * Write a signed byte to the <code>DataOutput</code>. - * - * @param value the signed byte to be written - */ -inline void writeByte(Buffer* buf, int8_t value) -{ - writeUnsigned(buf, (uint8_t)value); -} - -/** - * Read a signed byte from the <code>DataInput</code>. - * - * @param value output parameter to hold the signed byte read from stream - */ -inline void readByte(Buffer* buf, int8_t* value ) -{ - //checkBufferSize(1); - *value = *(buf->m_buf++); -} - -/** - * * Read a 16-bit signed integer from the <code>DataInput</code>. - * * - * * @param value output parameter to hold the 16-bit signed integer - * * read from stream - * */ -inline void readShort(Buffer* buf, int16_t* value ) -{ -// checkBufferSize(2); - readUnsignedShort(buf, (uint16_t*)value ); -} - - -/** - * * Read a 16-bit unsigned integer from the <code>DataInput</code>. - * * - * * @param value output parameter to hold the 16-bit unsigned integer - * * read from stream - * */ -inline void readUnsignedShort(Buffer* buf, uint16_t* value ) -{ -// checkBufferSize(2); - uint16_t tmp = *(buf->m_buf++); - tmp = (tmp << 8) | *(buf->m_buf++); - *value = tmp; -} - - -/** - * Read a 32-bit signed integer from the <code>DataInput</code>. - * - * @param value output parameter to hold the 32-bit signed integer - * read from stream - */ -inline void readInt(Buffer* buf, int32_t* value ) -{ - //checkBufferSize(4); - readUnsignedInt(buf, (uint32_t*)value ); -} - - -/** - * Read a 32-bit unsigned integer from the <code>DataInput</code>. - * - * @param value output parameter to hold the 32-bit unsigned integer - * read from stream - */ -inline void readUnsignedInt(Buffer* buf, uint32_t* value ) -{ - //checkBufferSize(4); - uint32_t tmp = *(buf->m_buf++); - tmp = (tmp << 8) | *(buf->m_buf++); - tmp = (tmp << 8) | *(buf->m_buf++); - tmp = (tmp << 8) | *(buf->m_buf++); - *value = tmp; -} - - - - -/** - * Write an array of unsigned bytes to the <code>DataOutput</code>. - * - * @param value the array of unsigned bytes to be written - * @param len the number of bytes from the start of array to be written - */ -inline void writeUnsignedBytes(Buffer* buf, const uint8_t* bytes, int32_t len ) -{ - if (len >= 0) { - ensureCapacity(buf, len + 5 ); - writeArrayLen(buf, bytes==NULL ? 0 : len ); // length of bytes... - if ( len > 0 && bytes != NULL) { - memcpy( buf->m_buf, bytes, len ); - buf->m_buf += len; - } - } else { - writeByte(buf, (int8_t) -1 ); - } -} - -/** - * Write an array of signed bytes to the <code>DataOutput</code>. - * - * @param value the array of signed bytes to be written - * @param len the number of bytes from the start of array to be written - */ -inline void writeBytes(Buffer* buf, const int8_t* bytes, int32_t len ) -{ - // printf("bytes length: %d\n", len); - writeUnsignedBytes(buf, (const uint8_t*)bytes, len ); -} -/** - * Write a 32-bit unsigned integer value to the <code>DataOutput</code>. - * - * @param value the 32-bit unsigned integer value to be written - */ -inline void writeUnsignedInt( Buffer* buf,uint32_t value ) -{ - ensureCapacity(buf, 4 ); - *(buf->m_buf++) = (uint8_t)(value >> 24); - *(buf->m_buf++) = (uint8_t)(value >> 16); - *(buf->m_buf++) = (uint8_t)(value >> 8); - *(buf->m_buf++) = (uint8_t)value; -} - -/** - * Write a 32-bit signed integer value to the <code>DataOutput</code>. - * - * @param value the 32-bit signed integer value to be written - */ -inline void writeInt(Buffer* buf, int32_t value ) -{ - writeUnsignedInt(buf, (uint32_t)value ); -} - -/** - * Write a 64-bit unsigned integer value to the <code>DataOutput</code>. - * - * @param value the 64-bit unsigned integer value to be written - */ -inline void writeUnsignedLong( Buffer* buf,uint64_t value ) -{ - ensureCapacity(buf, 8 ); - *(buf->m_buf++) = (uint8_t)(value >> 56); - *(buf->m_buf++) = (uint8_t)(value >> 48); - *(buf->m_buf++) = (uint8_t)(value >> 40); - *(buf->m_buf++) = (uint8_t)(value >> 32); - *(buf->m_buf++) = (uint8_t)(value >> 24); - *(buf->m_buf++) = (uint8_t)(value >> 16); - *(buf->m_buf++) = (uint8_t)(value >> 8); - *(buf->m_buf++) = (uint8_t)value; -} - -/** - * Write a 64-bit signed integer value to the <code>DataOutput</code>. - * - * @param value the 64-bit signed integer value to be written - */ -inline void writeLong(Buffer* buf, int64_t value ) -{ - writeUnsignedLong(buf, (uint64_t)value ); -} - -/** - * Write a 16-bit unsigned integer value to the <code>DataOutput</code>. - * - * @param value the 16-bit unsigned integer value to be written - */ -inline void writeUnsignedShort( Buffer* buf,uint16_t value ) -{ - ensureCapacity(buf, 2 ); - *(buf->m_buf++) = (uint8_t)(value >> 8); - *(buf->m_buf++) = (uint8_t)value; -} - -/** - * Write a 16-bit signed integer value to the <code>DataOutput</code>. - * - * @param value the 16-bit signed integer value to be written - */ -inline void writeShort(Buffer* buf, int16_t value ) -{ - writeUnsignedShort(buf, (uint16_t)value ); -} - -/** - * Write a 32-bit signed integer array length value to the - * <code>DataOutput</code> in a manner compatible with java server's - * <code>DataSerializer.writeArrayLength</code>. - * - * @param value the 32-bit signed integer array length to be written - */ -inline void writeArrayLen(Buffer* buf, int32_t len ) -{ - if (len == -1) { - writeByte(buf, (int8_t) -1); - } else if (len <= 252) { // 252 is java's ((byte)-4 && 0xFF) - writeUnsigned(buf, (uint8_t)len); - } else if (len <= 0xFFFF) { - writeByte(buf, (int8_t) -2); - writeUnsignedShort(buf, (uint16_t)len); - } else { - writeByte(buf, (int8_t) -3); - writeInt(buf, len); - } -} - -/** - * Advance the buffer cursor by the given offset. - * - * @param offset the offset by which to advance the cursor - */ -void advanceCursor(Buffer* buf, uint32_t offset) -{ - buf->m_buf += offset; -} - -/** - * Rewind the buffer cursor by the given offset. - * - * @param offset the offset by which to rewind the cursor - */ -void rewindCursor(Buffer* buf, uint32_t offset) -{ - buf->m_buf -= offset; -} - -/** - * Get the length of current data in the internal buffer of - * <code>DataOutput</code>. - */ -inline uint32_t getBufferLength(Buffer* buf) { - return (uint32_t)( buf->m_buf - buf->m_bytes ); -} - -inline uint8_t* getBuffer(Buffer* buf) -{ - return buf->m_bytes; -} - -inline uint8_t* getCursor(Buffer* buf) { - return buf->m_buf; -} - -// make sure there is room left for the requested size item. -inline void ensureCapacity(Buffer* buf, uint32_t size ) -{ - uint32_t offset = (uint32_t)( buf->m_buf - buf->m_bytes ); - if ( (buf->m_size - offset) < size ) { - uint32_t newSize = buf->m_size * 2 + (8192 * (size / 8192)); - buf->m_size = newSize; - GF_RESIZE( buf->m_bytes, uint8_t, buf->m_size ); - buf->m_buf = buf->m_bytes + offset; - } -} - -inline void writeNoCheck(Buffer* buf, uint8_t value) -{ - //uint32_t offset = (uint32_t)( buf->m_buf - buf->m_bytes ); - //printf("%d:%d\n",offset, buf->m_size); - *(buf->m_buf++) = value; -} - - -inline void initBuf(Buffer* buf) -{ - GF_ALLOC( buf->m_bytes, uint8_t, 8192 ); - buf->m_buf = buf->m_bytes; - buf->m_size = 8192; -} - -inline void clearBuf(Buffer* buf) -{ - GF_FREE(buf->m_bytes); - buf->m_bytes = NULL; - buf->m_buf = NULL; - buf->m_size = 0; -} - -inline void writeASCII(Buffer* buf, const char* value) -{ - if ( value != NULL ) { - uint32_t length = (uint32_t)strlen( value ); - uint16_t len = (uint16_t)( length > 0xFFFF ? 0xFFFF : length ); - writeUnsignedShort(buf, len); - writeBytesOnly(buf, (int8_t*)value, len ); // K64 - } else { - writeShort(buf, (uint16_t)0); - } -} - -inline void writeBytesOnly(Buffer* buf, const int8_t* bytes, int32_t len) -{ - ensureCapacity(buf, len); - memcpy(buf->m_buf, bytes, len); - buf->m_buf += len; -} - http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/src/data_io.h ---------------------------------------------------------------------- diff --git a/src/cclient/src/data_io.h b/src/cclient/src/data_io.h deleted file mode 100644 index 12be8fa..0000000 --- a/src/cclient/src/data_io.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __C_GEMFIRE_DATAOUTPUT_H__ -#define __C_GEMFIRE_DATAOUTPUT_H__ - -#include <string.h> -#include <stdlib.h> -#include <stdint.h> - -/** - * @file - */ - -/** - * C style memory allocation that throws OutOfMemoryException - * if it fails - */ -#define GF_ALLOC(v,t,s) \ -{ \ - v = (t*)malloc((s) * sizeof(t)); \ -} - -/** - * C style memory re-allocation that throws OutOfMemoryException - * if it fails - */ -#define GF_RESIZE(v,t,s) \ -{ \ - v = (t*)realloc(v, (s) * sizeof(t)); \ -} - -#define GF_FREE(v) free(v) - -typedef struct { - // memory m_buffer to encode to. - uint8_t* m_bytes; - // cursor. - uint8_t* m_buf; - // size of m_bytes. - uint32_t m_size; -} Buffer; - -inline void writeUnsigned(Buffer* buf, uint8_t value); -inline void writeByte(Buffer* buf, int8_t value); -inline void writeUnsignedBytes(Buffer* buf, const uint8_t* bytes, int32_t len ); -inline void writeBytes(Buffer* buf, const int8_t* bytes, int32_t len ); -inline void writeBytesOnly(Buffer* buf, const int8_t* bytes, int32_t len ); -inline void writeUnsignedInt( Buffer* buf,uint32_t value ); -inline void writeInt(Buffer* buf, int32_t value ); -inline void writeUnsignedLong( Buffer* buf,uint64_t value ); -inline void writeLong(Buffer* buf, int64_t value ); -inline void writeUnsignedShort( Buffer* buf,uint16_t value ); -inline void writeShort(Buffer* buf, int16_t value ); -inline void writeArrayLen(Buffer* buf, int32_t len ); -inline void writeASCII(Buffer* buf, const char* value); -inline void writeNoCheck(Buffer* buf, uint8_t value); - -inline void readByte(Buffer* buf, int8_t* value ); -inline void readShort(Buffer* buf, int16_t* value ); -inline void readUnsignedShort(Buffer* buf, uint16_t* value ); -inline void readInt(Buffer* buf, int32_t* value ); -inline void readUnsignedInt(Buffer* buf, uint32_t* value ); - -void advanceCursor(Buffer* buf, uint32_t offset); -void rewindCursor(Buffer* buf, uint32_t offset); - -inline void initBuf(Buffer* buf); -inline void clearBuf(Buffer* buf); -inline uint32_t getBufferLength(Buffer* buf) ; -inline uint8_t* getBuffer(Buffer* buf) ; -inline uint8_t* getCursor(Buffer* buf) ; - -inline void ensureCapacity(Buffer* buf, uint32_t size ); - -#endif // __C_GEMFIRE_DATAOUTPUT_H__ http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/src/gf_client.c ---------------------------------------------------------------------- diff --git a/src/cclient/src/gf_client.c b/src/cclient/src/gf_client.c deleted file mode 100644 index d55f0d4..0000000 --- a/src/cclient/src/gf_client.c +++ /dev/null @@ -1,822 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include <netdb.h> -#include <netinet/in.h> -#include <sys/socket.h> -#include <arpa/inet.h> -#include <errno.h> -#include<pthread.h> -#include "data_io.h" -#include "gf_client.h" - - -#define RECIEVE_DATA(context, request, reply, len, resultcode) \ - recieveData(context, &reply, len, resultcode);\ -if(*resultcode != NO_ERROR)\ -{\ - clearBuf(&request);\ - clearBuf(&reply);\ - return;\ -} - -#define SEND_DATA(context, request, reply, resultcode) \ - sendData(context, getBuffer(&request), getBufferLength(&request), resultcode);\ -if(*resultcode != NO_ERROR)\ -{\ - clearBuf(&request);\ - clearBuf(&reply);\ - return;\ -} - - -#define CLIENT_TO_SERVER 100 -#define REPLY_OK 59 -#define SECURITY_CREDENTIALS_NONE 0 -#define VERSION_ORDINAL_651 7 // since NC 3510 -#define CONFLATEBYTE 0 -#define ADDRSIZE 4 -#define DCPORT 12334 -#define VMKIND 13 -#define ROLEARRLENGTH 0 -#define REGION_NAME "/ROOT-REGION" -#define TIMEOUT 5 -#define RAND_STRING_LEN 10 -const int32_t HEADER_LENGTH = 17; -static int32_t synch_counter = 2; -//static int32_t transactioID = 0; - - -#define MAXBUF 1024 - -enum TypeIdValues { - // Do not use IDs 5 and 6 which are used by .NET - // ManagedObject and ManagedObjectXml. If those are - // required then change those in GemfireTypeIdsM.hpp - - // keep the following in alphabetical order please. - Properties = 11, - BooleanArray = 26, - CharArray = 27, - RegionAttributes = 30, // because there's no equivalence in java - CacheableUndefined = 31, - Struct = 32, - NullObj = 41, - CacheableString = 42, - CacheableBytes = 46, - CacheableInt16Array = 47, - CacheableInt32Array = 48, - CacheableInt64Array = 49, - CacheableFloatArray = 50, - CacheableDoubleArray = 51, - CacheableObjectArray = 52, - CacheableBoolean = 53, - CacheableWideChar = 54, - CacheableByte = 55, - CacheableInt16 = 56, - CacheableInt32 = 57, - CacheableInt64 = 58, - CacheableFloat = 59, - CacheableDouble = 60, - CacheableDate = 61, - CacheableFileName = 63, - CacheableStringArray = 64, - CacheableArrayList = 65, - CacheableHashSet = 66, - CacheableHashMap = 67, - CacheableTimeUnit = 68, - CacheableNullString = 69, - CacheableHashTable = 70, - CacheableVector = 71, - CacheableIdentityHashMap = 72, - CacheableLinkedHashSet = 73, - CacheableStack = 74, - CacheableASCIIString = 87, - CacheableASCIIStringHuge = 88, - CacheableStringHuge = 89 -}; -enum IdValues { - // keep the following in alphabetical order please. - ObjectTypeImpl = -61, - StructTypeImpl = -60, - CollectionTypeImpl = -59, - FixedIDDefault = 0, - FixedIDByte = 1, - FixedIDShort = 2, - FixedIDInt = 3, - FixedIDNone = 4, - CacheableToken = 14, // because there's no equivalence in java - CacheableObjectPartList = 25, - EventId = 36, - InterestResultPolicy = 37, - ClientProxyMembershipId = 38, - CacheableUserData4 = 37, - CacheableUserData2 = 38, - CacheableUserData = 39, - CacheableUserClass = 40, - Class = 43, - JavaSerializable = 44, - DataSerializable = 45, - InternalDistributedMember = 92, - EntryEventImpl = 105, - RegionEventImpl = 108, - ClientHealthStats = -126, - GatewayEventCallbackArgument = -56, // 0xC8 - ClientConnectionRequest = -53, - ClientConnectionResponse = -50, - QueueConnectionRequest = -52, - QueueConnectionResponse = -49, - LocatorListRequest = -54, - LocatorListResponse = -51, - GetAllServersRequest = -43, - GetAllServersResponse = -42, - ClientReplacementRequest= -48 -}; -typedef enum { - /* Server couldn't read message; handle it like a server side - exception that needs retries */ - INVALID = -1, - REQUEST = 0, - RESPONSE /* 1 */, - EXCEPTION /* 2 */, - REQUEST_DATA_ERROR /* 3 */, - DATA_NOT_FOUND_ERROR /* 4 Not in use */, - PING /* 5 */, - REPLY /* 6 */, - PUT /* 7 */, - PUT_DATA_ERROR /* 8 */, - DESTROY /* 9 */, - DESTROY_DATA_ERROR /* 10 */, - DESTROY_REGION /* 11 */, - DESTROY_REGION_DATA_ERROR /* 12 */, - CLIENT_NOTIFICATION /* 13 */, - UPDATE_CLIENT_NOTIFICATION /* 14 */, - LOCAL_INVALIDATE /* 15 */, - LOCAL_DESTROY /* 16 */, - LOCAL_DESTROY_REGION /* 17 */, - CLOSE_CONNECTION /* 18 */, - PROCESS_BATCH /* 19 */, - REGISTER_INTEREST /* 20 */, - REGISTER_INTEREST_DATA_ERROR /* 21 */, - UNREGISTER_INTEREST /* 22 */, - UNREGISTER_INTEREST_DATA_ERROR /* 23 */, - REGISTER_INTEREST_LIST /* 24 */, - UNREGISTER_INTEREST_LIST /* 25 */, - UNKNOWN_MESSAGE_TYPE_ERROR /* 26 */, - LOCAL_CREATE /* 27 */, - LOCAL_UPDATE /* 28 */, - CREATE_REGION /* 29 */, - CREATE_REGION_DATA_ERROR /* 30 */, - MAKE_PRIMARY /* 31 */, - RESPONSE_FROM_PRIMARY /* 32 */, - RESPONSE_FROM_SECONDARY /* 33 */, - QUERY /* 34 */, - QUERY_DATA_ERROR /* 35 */, - CLEAR_REGION /* 36 */, - CLEAR_REGION_DATA_ERROR /* 37 */, - CONTAINS_KEY /* 38 */, - CONTAINS_KEY_DATA_ERROR /* 39 */, - KEY_SET /* 40 */, - KEY_SET_DATA_ERROR /* 41 */, - EXECUTECQ_MSG_TYPE /* 42 */, - EXECUTECQ_WITH_IR_MSG_TYPE /*43 */, - STOPCQ_MSG_TYPE /*44*/, - CLOSECQ_MSG_TYPE /*45 */, - CLOSECLIENTCQS_MSG_TYPE /*46*/, - CQDATAERROR_MSG_TYPE /*47 */, - GETCQSTATS_MSG_TYPE /*48 */, - MONITORCQ_MSG_TYPE /*49 */, - CQ_EXCEPTION_TYPE /*50 */, - REGISTER_INSTANTIATORS = 51 /* 51 */, - PERIODIC_ACK = 52 /* 52 */, - CLIENT_READY /* 53 */, - CLIENT_MARKER /* 54 */, - INVALIDATE_REGION /* 55 */, - PUTALL /* 56 */, - GET_ALL = 57 /* 57 */, - GET_ALL_DATA_ERROR /* 58 */, - EXECUTE_REGION_FUNCTION = 59 /* 59 */, - EXECUTE_REGION_FUNCTION_RESULT /* 60 */, - EXECUTE_REGION_FUNCTION_ERROR /* 61 */, - EXECUTE_FUNCTION /* 62 */, - EXECUTE_FUNCTION_RESULT /* 63 */, - EXECUTE_FUNCTION_ERROR /* 64 */, - CLIENT_REGISTER_INTEREST = 65 /* 65 */, - CLIENT_UNREGISTER_INTEREST = 66, - REGISTER_DATASERIALIZERS = 67, - REQUEST_EVENT_VALUE = 68, - REQUEST_EVENT_VALUE_ERROR = 69, /*69*/ - PUT_DELTA_ERROR = 70, /*70*/ - GET_CLIENT_PR_METADATA = 71, /*71*/ - RESPONSE_CLIENT_PR_METADATA = 72, /*72*/ - GET_CLIENT_PARTITION_ATTRIBUTES = 73, /*73*/ - RESPONSE_CLIENT_PARTITION_ATTRIBUTES =74, /*74*/ - GET_CLIENT_PR_METADATA_ERROR = 75, /*75*/ - GET_CLIENT_PARTITION_ATTRIBUTES_ERROR = 76, /*76*/ - USER_CREDENTIAL_MESSAGE = 77, - REMOVE_USER_AUTH = 78, - QUERY_WITH_PARAMETERS = 80 - -} MsgType; -/* -int32_t incTransactionID() -{ - return 1;//transactioID++; -} -*/ -int64_t getAndIncEid(CONTEXT* context) -{ - return context->eidSeq++; -} - -void printData(uint8_t* buf, int32_t len) -{ - int32_t i; - printf("\n"); - for(i = 0; i < len; i++) - { - printf("%d ", buf[i]); - } - printf("\n"); -} - -void recieveData(CONTEXT* context, Buffer* buf, uint32_t len, int32_t* resultcode) -{ - time_t startTime = time(NULL); - uint32_t origLen = len; - - while(len > 0 && (time(NULL) - startTime) < TIMEOUT ) - { - int8_t buffer[MAXBUF]; - bzero(buffer, MAXBUF); - int32_t recLen = recv(context->sockfd, buffer, len > MAXBUF?MAXBUF:len, 0); - if(recLen > 0) - { - len -= recLen; - writeBytesOnly(buf, buffer, recLen); - } else if(recLen == 0) - { - *resultcode = CONNECTION_ERROR; - //printf("closed connection"); - return; - } - } - - //printf("recieve"); - //printData(getBuffer(buf), getBufferLength(buf)); - - if(len == 0) - rewindCursor(buf, origLen); - *resultcode = (len > 0)?CONNECTION_ERROR:NO_ERROR; -} - - - -void sendData(CONTEXT* context, uint8_t* buf, int32_t len, int32_t* resultcode) -{ - time_t startTime = time(NULL); - uint32_t sentLen = 0; - //printf("send[%d]", len); - //printData(buf, len); - while(len > 0 && (time(NULL) - startTime) < TIMEOUT ) - { - int32_t sendLen = send(context->sockfd, (buf + sentLen), len, 0); - //printf("sent %d bytes\n", sendLen); - if(sendLen > 0) - { - len -= sendLen; - sentLen += sendLen; - } else if(sendLen == 0) - { - *resultcode = CONNECTION_ERROR; - //printf("closed connection"); - return; - } - - } - - *resultcode = (len > 0)?CONNECTION_ERROR:NO_ERROR; -} - -CONTEXT* createContext(char* host, char* port) -{ - - struct addrinfo hints; - struct addrinfo *result, *rp; - int sfd, s; - - /* Obtain address(es) matching host/port */ - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = 0; - hints.ai_protocol = 0; - - s = getaddrinfo(host, port, &hints, &result); - if (s != 0) { - return NULL; - } - - /* getaddrinfo() returns a list of address structures. - Try each address until we successfully connect(2). - If socket(2) (or connect(2)) fails, we (close the socket - and) try the next address. */ - - for (rp = result; rp != NULL; rp = rp->ai_next) { - sfd = socket(rp->ai_family, rp->ai_socktype, - rp->ai_protocol); - struct timeval tv; - int32_t timeout=1000; - - tv.tv_sec = timeout / 1000 ; - tv.tv_usec = ( timeout % 1000) * 1000 ; - - setsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char - *)&tv, sizeof tv); - if (sfd == -1) - continue; - - if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) - break; /* Success */ - - close(sfd); - } - - if (rp == NULL) { /* No address succeeded */ - //fprintf(stderr, "Could not connect\n"); - //exit(EXIT_FAILURE); - return NULL; - } - - CONTEXT* context = (CONTEXT*)malloc(sizeof(CONTEXT)); - context->sockfd = sfd; - context->eidSeq = 0; - - return context; -} - -void createRandString(char *randString) -{ - const char selectChars[] = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; - const uint32_t numChars = (sizeof(selectChars) / sizeof(char)) - 1; - strcpy(randString, "GFNative_"); - uint32_t startIndex = strlen(randString); - uint32_t seed = getpid() + time(NULL); - srand(seed); - uint32_t index; - for (index = 0; index < RAND_STRING_LEN; ++index) { - randString[startIndex + index] = selectChars[rand() % numChars]; - } - randString[startIndex + RAND_STRING_LEN] = '\0'; -} - -void writeClientProxyMembershipId(Buffer* buf) -{ - struct hostent *host; /* host information */ - //struct in_addr h_addr; /* internet address */ - char hostName[1024]; - gethostname(hostName, 1023); - host = gethostbyname(hostName); - char randString[1024]; - createRandString(randString); - - Buffer memId; - initBuf(&memId); - - writeByte(&memId, (int8_t)FixedIDByte); - writeByte(&memId, (int8_t)InternalDistributedMember); - writeArrayLen(&memId, ADDRSIZE); - writeInt(&memId, (int32_t)(*(host->h_addr_list[0]))); - //m_memID.writeInt((int32_t)hostPort); - writeInt(&memId, (int32_t)synch_counter); - writeByte(&memId, (int8_t)CacheableASCIIString); - writeASCII(&memId, host->h_name ); - writeByte(&memId, (int8_t)0); // splitbrain flags - - writeInt(&memId, (int32_t)DCPORT); - - writeInt(&memId, (int32_t)getpid()); - writeByte(&memId, (int8_t)VMKIND); - writeArrayLen(&memId, ROLEARRLENGTH); - writeByte(&memId, (int8_t)CacheableASCIIString); - writeASCII(&memId, "default_GemfireDS"); - writeByte(&memId, (int8_t)CacheableASCIIString); - writeASCII(&memId, randString); - writeByte(&memId, (int8_t)CacheableASCIIString); - writeASCII(&memId, ""); - writeInt(&memId, (int32_t)300); - writeUnsignedBytes(buf, getBuffer(&memId), getBufferLength(&memId)); - - - clearBuf(&memId); -} - -void doHandshake(CONTEXT* context, int32_t* resultcode) -{ - Buffer request; - initBuf(&request); - Buffer reply; - initBuf(&reply); - *resultcode = NO_ERROR; - - writeByte(&request, (int8_t)CLIENT_TO_SERVER ); - writeByte(&request, (int8_t)VERSION_ORDINAL_651); - writeByte(&request, (int8_t)REPLY_OK); - writeInt(&request, (int32_t)0x7fffffff - 10000 ); - // Write header for byte FixedID since GFE 5.7 - writeByte(&request, (int8_t)FixedIDByte); - //Writing byte for ClientProxyMembershipID class id=38 as registered on the java server. - writeByte(&request, (int8_t)ClientProxyMembershipId); - /* calc memId */ - writeClientProxyMembershipId(&request); - // writeBytes(&request, (int8_t *)memIdBuffer, memIdBufferLength); - writeInt(&request,(int32_t)1); - writeByte(&request, (int8_t)CONFLATEBYTE); - writeUnsigned(&request, (uint8_t)SECURITY_CREDENTIALS_NONE); - - SEND_DATA(context, request, reply, resultcode) - - //sendData(context, getBuffer(&buf), getBufferLength(&buf)); - /*---Get "Hello?"---*/ - //int recLen = 1; - // recieveData(context, &reply, 7); - RECIEVE_DATA(context, request, reply, 7, resultcode) - - int8_t acceptance_code; - int8_t serverQueueStatus; - int8_t recvMsgLenByte; - int32_t queueSize; - readByte(&reply, &acceptance_code); - readByte(&reply, &serverQueueStatus); - readInt(&reply, &queueSize); - readByte(&reply, &recvMsgLenByte); - int32_t recvMsgLen = recvMsgLenByte; - if (recvMsgLen== -2) { - int16_t recvMsgLenShort = 0; - // recieveData(context, &reply, 2); - RECIEVE_DATA(context, request, reply, 2, resultcode) - readShort(&reply, &recvMsgLenShort); - recvMsgLen = recvMsgLenShort; - } - else if (recvMsgLen == -3) { - // recieveData(context, &reply, 4); - RECIEVE_DATA(context, request, reply, 4, resultcode) - readInt(&reply, &recvMsgLen); - } - //recieveData(context, &reply, recvMsgLen); - RECIEVE_DATA(context, request, reply, recvMsgLen, resultcode) - advanceCursor(&reply, recvMsgLen); - uint16_t recvMsgLen2 = 0; - //recieveData(context, &reply, 2); - RECIEVE_DATA(context, request, reply,2, resultcode) - readUnsignedShort(&reply, &recvMsgLen2); - //recieveData(context, &reply, recvMsgLen2); - RECIEVE_DATA(context, request, reply, recvMsgLen2, resultcode) - advanceCursor(&reply, recvMsgLen2); - int8_t isDeltaEnabledOnServer; - //recieveData(context, &reply, 1); - RECIEVE_DATA(context, request, reply, 1, resultcode) - readByte(&reply, &isDeltaEnabledOnServer); - if(acceptance_code != REPLY_OK) - { - *resultcode = HANDSHAKE_ERROR; - } - clearBuf(&request); - clearBuf(&reply); -} - - -void gf_write_header(Buffer* buf, uint32_t msgType, uint32_t numOfParts) -{ - - writeInt(buf, (int32_t)msgType); - writeInt(buf, (int32_t)0); // write a dummy message len('0' here). At the end write the length at the (buffer + 4) offset. - writeInt(buf, (int32_t)numOfParts); - writeInt(buf, (int32_t)1); - writeByte(buf, (int8_t)0x0); -} - -void write_region_part(Buffer* buf, char* regionName) -{ - int32_t len = strlen(regionName); - writeInt(buf, len); - writeByte(buf, (int8_t)0); // isObject = 0 - writeBytesOnly(buf, (int8_t *)regionName, len); -} - -void write_null_object(Buffer* buf) -{ - //write size - writeInt(buf, (int32_t)1); - //write isobject - writeByte(buf, (int8_t)1); - //write actual object - writeByte(buf, (int8_t)NullObj); -} - -void write_int_part(Buffer* buf, int32_t intValue) -{ - writeInt(buf, (int32_t) 4); - writeByte(buf, (int8_t) 0); - writeInt(buf, intValue); -} - -void write_string_part(Buffer* buf, const char* strValue) -{ - //write size - writeInt(buf, (int32_t)0); - //write isobject - writeByte(buf, (int8_t)1); - int32_t before = getBufferLength(buf); - writeByte(buf, (int8_t)CacheableASCIIString); - writeASCII(buf, strValue); - int32_t after = getBufferLength(buf); - int32_t sizeOfObj = after - before; - rewindCursor(buf, sizeOfObj + 1 + 4); - writeInt(buf, sizeOfObj); - advanceCursor(buf, sizeOfObj + 1); -} - -void write_bool_part(Buffer* buf, int8_t boolValue) -{ - //write size - writeInt(buf, (int32_t)2); - //write isobject - writeByte(buf, (int8_t)1); - writeByte(buf, (int8_t)CacheableBoolean); - writeByte(buf, (int8_t)boolValue); -} - -void write_bytes_part(Buffer* buf, const int8_t* bytes, int32_t len) -{ - //write size - writeInt(buf, (int32_t)1); - //write isobject - writeByte(buf, (int8_t)0); - int32_t before = getBufferLength(buf); - writeBytesOnly(buf, bytes, len); - int32_t after = getBufferLength(buf); - int32_t sizeOfObj = after - before; - rewindCursor(buf, sizeOfObj + 1 + 4); - writeInt(buf, sizeOfObj); - advanceCursor(buf, sizeOfObj + 1); -} - -void write_id_part(CONTEXT* context, Buffer* buf) -{ - // Write EventId threadid and seqno. - int32_t idsBufferLength = 18; - writeInt(buf, idsBufferLength); - writeUnsigned(buf, (uint8_t) 0); - char longCode = 3; - writeUnsigned(buf, (uint8_t) longCode); - writeLong(buf, pthread_self()); - writeUnsigned(buf, (uint8_t) longCode); - writeLong(buf, getAndIncEid(context)); -} - -void write_message_length(Buffer* buf) -{ - uint32_t totalLen = getBufferLength(buf); - uint32_t g_headerLen = 17; - uint32_t msgLen = totalLen - g_headerLen; - //printf("msglen: %d\n", msgLen); - rewindCursor(buf, totalLen - 4); // msg len is written after the msg type which is of 4 bytes ... - writeInt(buf, (int32_t)msgLen); - advanceCursor(buf, totalLen - 8); // after writing 4 bytes for msg len you are already 8 bytes ahead from the beginning. -} - -void gf_put(CONTEXT * context, const char * uuid, const int8_t * data, int32_t len, int32_t * resultcode) -{ - Buffer request; - initBuf(&request); - Buffer reply; - initBuf(&reply); - *resultcode = NO_ERROR; - - gf_write_header(&request, PUT, 7); - write_region_part(&request, REGION_NAME); - write_null_object(&request); - write_int_part(&request, 0); - write_string_part(&request, uuid); - write_bool_part(&request, 0); - write_bytes_part(&request, data, len); - write_id_part(context, &request); - write_message_length(&request); - - SEND_DATA(context, request, reply, resultcode) - // int err = sendData(context, getBuffer(&buf), getBufferLength(&buf)); - /*---Get "Hello?"---*/ - //int recLen = 1; - - RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode) - //err = recieveData(context, &reply, HEADER_LENGTH); - //printf("put error: %d\n", *resultcode); - int32_t msgType; - int32_t msgLen; - - readInt(&reply, &msgType); - readInt(&reply, &msgLen); - advanceCursor(&reply, HEADER_LENGTH - 8); - - RECIEVE_DATA(context, request, reply, msgLen, resultcode) - if(msgType != REPLY) - { - *resultcode = OPERATION_ERROR; - clearBuf(&request); - clearBuf(&reply); - } - //err = recieveData(context, &reply, msgLen); -} - -void gf_get(CONTEXT * context, const char * uuid, int8_t* data, uint32_t len, int32_t * resultcode) -{ - Buffer request; - initBuf(&request); - Buffer reply; - initBuf(&reply); - *resultcode = NO_ERROR; - - gf_write_header(&request, REQUEST, 2); - write_region_part(&request, REGION_NAME); - write_string_part(&request, uuid); - write_message_length(&request); - - SEND_DATA(context, request, reply, resultcode) - - //int err = sendData(context, getBuffer(&buf), getBufferLength(&buf)); - - RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode) - //err = recieveData(context, &reply, HEADER_LENGTH); - int32_t msgType; - int32_t msgLen; - - readInt(&reply, &msgType); - readInt(&reply, &msgLen); - advanceCursor(&reply, HEADER_LENGTH - 8); - - //err = recieveData(context, &reply, msgLen); - RECIEVE_DATA(context, request, reply, msgLen, resultcode) - if(msgType != RESPONSE) - { - *resultcode = OPERATION_ERROR; - clearBuf(&request); - clearBuf(&reply); - return; - } - uint32_t dataLen; - readUnsignedInt(&reply, &dataLen); - int8_t isObj; - readByte(&reply, &isObj); - memcpy(data, getCursor(&reply), dataLen); -} - -void gf_destroy(CONTEXT * context, const char * uuid, int32_t * resultcode) -{ - Buffer request; - initBuf(&request); - Buffer reply; - initBuf(&reply); - *resultcode = NO_ERROR; - - gf_write_header(&request, DESTROY, 5); - write_region_part(&request, REGION_NAME); - write_string_part(&request, uuid); - write_null_object(&request); - write_null_object(&request); - write_id_part(context, &request); - write_message_length(&request); - - SEND_DATA(context, request, reply, resultcode) - - // int err = sendData(context, getBuffer(&buf), getBufferLength(&buf)); - /*---Get "Hello?"---*/ - //int recLen = 1; - - RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode) - - // err = recieveData(context, &reply, HEADER_LENGTH); - //printf("destroy error: %d\n", *resultcode); - int32_t msgType; - int32_t msgLen; - - readInt(&reply, &msgType); - readInt(&reply, &msgLen); - advanceCursor(&reply, HEADER_LENGTH - 8); - - // err = recieveData(context, &reply, msgLen); - RECIEVE_DATA(context, request, reply, msgLen, resultcode) - if(msgType != REPLY) - { - *resultcode = OPERATION_ERROR; - clearBuf(&request); - clearBuf(&reply); - } -} - -void gf_ping(CONTEXT* context, int32_t* resultcode) -{ - Buffer request; - initBuf(&request); - Buffer reply; - initBuf(&reply); - *resultcode = NO_ERROR; - - writeInt(&request, (int32_t)PING); - writeInt(&request, (int32_t)0);// 17 is fixed message len ... PING only has a header. - writeInt(&request, (int32_t)0);// Number of parts. - writeInt(&request, (int32_t)0); - writeByte(&request, (int8_t)0);// Early ack is '0'. - SEND_DATA(context, request, reply, resultcode) - RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode) - - int32_t msgType; - int32_t msgLen; - - readInt(&reply, &msgType); - readInt(&reply, &msgLen); - advanceCursor(&reply, HEADER_LENGTH - 8); - - // err = recieveData(context, &reply, msgLen); - RECIEVE_DATA(context, request, reply, msgLen, resultcode) - if(msgType != REPLY) - { - *resultcode = OPERATION_ERROR; - clearBuf(&request); - clearBuf(&reply); - } -} - -void gf_disconnect(CONTEXT * context, int32_t * resultcode) -{ - Buffer request; - initBuf(&request); - Buffer reply; - initBuf(&reply); - *resultcode = NO_ERROR; - - writeInt(&request, (int32_t)CLOSE_CONNECTION); - writeInt(&request,(int32_t)6); - writeInt(&request,(int32_t)1);// Number of parts. - //int32_t txId = TcrMessage::m_transactionId++; - writeInt(&request,(int32_t)0); - writeByte(&request, (int8_t)0);// Early ack is '0'. - // last two parts are not used ... setting zero in both the parts. - writeInt(&request,(int32_t)1); // len is 1 - writeByte(&request,(int8_t)0);// is obj is '0'. - // cast away constness here since we want to modify this - writeByte(&request,(int8_t)0);// keepalive is '0'. - SEND_DATA(context, request, reply, resultcode) - - int32_t error = close(context->sockfd); - if(error == 0) { - *resultcode = NO_ERROR; - } else { - *resultcode = CONNECTION_ERROR; - } - - free(context); -} - -CONTEXT* gf_connect(char* host, char* port, int32_t* resultcode) -{ - CONTEXT* context = createContext(host, port); - - if(context == NULL) - { - *resultcode = CONNECTION_ERROR; - //printf("CONNECTION ERROR"); - } else { - doHandshake(context, resultcode); - if(*resultcode != NO_ERROR) - { - int32_t error; - //printf("HANDSHAKE ERROR"); - *resultcode = HANDSHAKE_ERROR; - gf_disconnect(context, &error); - context = NULL; - } - } - - return context; -} - http://git-wip-us.apache.org/repos/asf/geode-native/blob/c38580a5/src/cclient/src/gf_client.h ---------------------------------------------------------------------- diff --git a/src/cclient/src/gf_client.h b/src/cclient/src/gf_client.h deleted file mode 100644 index 7ed34a0..0000000 --- a/src/cclient/src/gf_client.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __C_GEMFIRE_CLIENT_H__ -#define __C_GEMFIRE_CLIENT_H__ - -#include <stdint.h> - -typedef struct -{ - int32_t sockfd; - int64_t eidSeq; -} CONTEXT; - - -enum error_codes { - NO_ERROR, - CONNECTION_ERROR = 1, - HANDSHAKE_ERROR, - OPERATION_ERROR -}; - -/* - * Establish a connection with the specified GemFire endpoint. - * - * @param host the hostname to connect. - * @param port the port to connect. - * @param resultcode the result code returned to the caller. - * @returns a pointer to the context required for further operations. - */ - -CONTEXT* gf_connect(char * host, char* port, int32_t * resultcode); - -/* - * Close down a connection previously established with a GemFire endpoint. - * - * @param CONTEXT the context of the connection to close. - * @param resultcode the result code returned to the caller. - */ - -void gf_disconnect(CONTEXT * context, int32_t * resultcode); - -/* - * Store data associated with the specified UUID into the GemFire system. - * Callee does not free the data. - * - * @param CONTEXT the context of the connection to use. - * @param region the GemFire region where the data goes. - * @param uuid the UUID key associated with the data. - * @param data a pointer to the data to store. - * @param len the byte length of the data. - * @param resultcode the result code returned to the caller. - */ - -void gf_put(CONTEXT * context, const char * uuid, const int8_t * data, int32_t len, int32_t * resultcode); - -/* - * Read data associated with the specified UUID from GemFire. - * Caller must free the returned data. - * - * @param CONTEXT the context of the connection to use. - * @param region the GemFire region from where the data is retrieved. - * @param uuid the UUID key associated with the data. - * @param len the byte length of the data being returned. - * @param resultcode the result code returned to the caller. - */ - -void gf_get(CONTEXT * context, const char * uuid, int8_t* data, uint32_t len, int32_t * resultcode); - -/* - * Destroy the data associated with the specified UUID key from the GemFire system. - * - * @param CONTEXT the context of the connection to use. - * @param region the GemFire region from where the data is cleared. - * @param uuid the UUID key associated with the data. - * @param resultcode the result code returned to the caller. - */ - -void gf_destroy(CONTEXT * context, const char * uuid, int32_t * resultcode); - -/* - * Send a ping message to the server - * - * @param CONTEXT the context of the connection to use. - * @param resultcode the result code returned to the caller. - */ - -void gf_ping(CONTEXT* context, int32_t* resultcode); - -#endif -
