00001 #include "lsm_ipc.h" 00002 00003 #include <iostream> 00004 #include <stdlib.h> 00005 00006 00007 std::string gen_random(int len) 00008 { 00009 static const char alphanum[] = 00010 "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; 00011 std::string rc(len, 'x'); 00012 00013 for (int i = 0; i < len; ++i) { 00014 rc[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; 00015 } 00016 return rc; 00017 } 00018 00019 00020 void TestIt(int fd) 00021 { 00022 int rc = 0; 00023 int ec = 0; 00024 Transport t(fd); 00025 00026 for (int i = 1; i < 1024 * 1024 * 16; i += 1) { 00027 00028 std::string msg = gen_random(i); 00029 00030 std::cout << "sending msg" << std::endl; 00031 rc = t.sendMsg(msg, ec); 00032 std::cout << "message sent: " << rc << std::endl; 00033 if (rc == 0) { 00034 00035 std::cout << "Receiving msg" << std::endl; 00036 std::string rmsg = t.recvMsg(ec); 00037 std:: 00038 cout << "Message received " << rmsg.size() << " Byte(s)" << 00039 std::endl; 00040 00041 if (rmsg.size() > 0) { 00042 00043 if (msg != rmsg) { 00044 std::cout << "Data miss-compare" << std::endl; 00045 std::cout << "Recv: " << rmsg << std::endl; 00046 } 00047 } else { 00048 std::cout << "Error recv: " << ec << std::endl; 00049 break; 00050 } 00051 } else { 00052 std::cout << "Error send: " << ec << std::endl; 00053 break; 00054 } 00055 } 00056 } 00057 00058 00059 00060 int main(void) 00061 { 00062 std::string path("/tmp/testing"); 00063 00064 int ec = 0; 00065 int fd = 0; 00066 00067 fd = Transport::getSocket(path, ec); 00068 00069 if (fd >= 0) { 00070 TestIt(fd); 00071 } else { 00072 std::cout << "Error getting connected socket: " << ec << std::endl; 00073 } 00074 00075 return 0; 00076 }