summaryrefslogtreecommitdiffstats
path: root/test/src/test-sockets.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-08-13 11:48:26 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-08-13 11:48:26 (GMT)
commit02f52d15e7df2500c0c6e96660a43a985add16e8 (patch)
treed4ccfdd7d1070201f39a9589b35e02a39ec179c8 /test/src/test-sockets.cpp
parentc30b602cdb5ede809b960e35fc7e702b7f1f76e2 (diff)
downloaduscxml-02f52d15e7df2500c0c6e96660a43a985add16e8.zip
uscxml-02f52d15e7df2500c0c6e96660a43a985add16e8.tar.gz
uscxml-02f52d15e7df2500c0c6e96660a43a985add16e8.tar.bz2
Builds for Raspberry and
started VoiceXML HTTP integration
Diffstat (limited to 'test/src/test-sockets.cpp')
-rw-r--r--test/src/test-sockets.cpp67
1 files changed, 66 insertions, 1 deletions
diff --git a/test/src/test-sockets.cpp b/test/src/test-sockets.cpp
index a02eb9c..ad567f7 100644
--- a/test/src/test-sockets.cpp
+++ b/test/src/test-sockets.cpp
@@ -1,4 +1,5 @@
#include "uscxml/config.h"
+#include "uscxml/Convenience.h"
#include "uscxml/server/Socket.h"
#include <iostream>
#include <stdexcept>
@@ -25,6 +26,28 @@ public:
};
};
+int packetSeq = 0;
+
+class LogServer : public ServerSocket {
+public:
+ LogServer(int domain, int type, int protocol) : ServerSocket(domain, type, protocol) {}
+ virtual void readCallback(const char* data, size_t size, Connection& conn) {
+ std::string content(data, size);
+ std::cout << "Server got: " << content << std::endl;
+ };
+};
+
+class CountingPacketServer : public PacketServerSocket {
+public:
+ CountingPacketServer(int domain, int type, int protocol, const std::string& sep) : PacketServerSocket(domain, type, protocol, sep) {}
+ virtual void readCallback(const std::string& packet, Connection& conn) {
+// std::cout << "-- " << packet << std::endl;
+ size_t seq = strTo<size_t>(packet);
+ assert(seq == packetSeq);
+ packetSeq++;
+ };
+};
+
class TestClient : public ClientSocket {
public:
TestClient(int domain, int type, int protocol) : ClientSocket(domain, type, protocol) {}
@@ -45,7 +68,49 @@ int main(int argc, char** argv) {
evthread_use_windows_threads();
#endif
- if (0) {
+ if (1) {
+ packetSeq = 0;
+ CountingPacketServer server(PF_INET, SOCK_STREAM, 0, std::string("tadaa!"));
+// LogServer server(PF_INET, SOCK_STREAM, 0);
+ server.listen("*", 1235);
+ server.setBlockSizeRead(1);
+
+ TestClient client(PF_INET, SOCK_STREAM, 0);
+ client.connect("127.0.0.1", 1235);
+
+ int iterations = 1000;
+ std::stringstream contentSS;
+ for (int i = 0; i < iterations; i++) {
+ contentSS << toStr(i);
+ contentSS << "tadaa!";
+ }
+ client.write(contentSS.str());
+
+ while(packetSeq != iterations)
+ usleep(10000);
+ }
+
+ if (1) {
+ packetSeq = 0;
+ CountingPacketServer server(PF_INET, SOCK_STREAM, 0, std::string("\0", 1));
+ server.listen("*", 1235);
+
+ TestClient client(PF_INET, SOCK_STREAM, 0);
+ client.connect("127.0.0.1", 1235);
+
+ int iterations = 1000;
+ for (int i = 0; i < iterations; i++) {
+ client.write(toStr(i));
+ client.write("\0", 1);
+ }
+
+ while(packetSeq != iterations)
+ usleep(10000);
+ }
+
+ exit(0);
+
+ if (1) {
// start server socket and connect
int iterations = 100;