summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp2
-rw-r--r--src/uscxml/server/Socket.cpp47
-rw-r--r--src/uscxml/server/Socket.h4
3 files changed, 33 insertions, 20 deletions
diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp
index 67a2371..1c5b98a 100644
--- a/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp
+++ b/src/uscxml/plugins/ioprocessor/modality/MMIMessages.cpp
@@ -160,7 +160,7 @@ Arabica::DOM::Document<std::string> ContentRequest::toXML(bool encapsulateInMMI)
Element<std::string> msgElem = Element<std::string>(doc.getDocumentElement().getFirstChild());
if (contentURL.href.size() > 0) {
- Element<std::string> contentURLElem = doc.createElementNS(nameSpace, "contentURL");
+ Element<std::string> contentURLElem = doc.createElementNS(nameSpace, "ContentURL");
contentURLElem.setAttributeNS(nameSpace, "href", contentURL.href);
contentURLElem.setAttributeNS(nameSpace, "fetchtimeout", contentURL.fetchTimeout);
contentURLElem.setAttributeNS(nameSpace, "max-age", contentURL.maxAge);
diff --git a/src/uscxml/server/Socket.cpp b/src/uscxml/server/Socket.cpp
index 2d474ea..fc79357 100644
--- a/src/uscxml/server/Socket.cpp
+++ b/src/uscxml/server/Socket.cpp
@@ -19,6 +19,7 @@
#include "Socket.h"
+#include "uscxml/Common.h" // for Data, Event
#include "uscxml/Message.h" // for Data, Event
#include "uscxml/config.h" // for OPENSSL_FOUND
@@ -46,14 +47,6 @@ Socket::Socket(int domain, int type, int protocol) {
if (_socketFD == -1)
throw std::runtime_error(std::string("socket: ") + strerror(errno));
-#ifndef WIN32
- {
- int one = 1;
- if (setsockopt(_socketFD, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) != 0) {
- throw std::runtime_error(std::string("setsockopt: ") + strerror(errno));
- }
- }
-#endif
}
@@ -300,16 +293,25 @@ void ServerSocket::listen(const std::string& address, int port) {
setupSockAddr(address, port);
bind();
- int reuseaddr_on = 1;
- setsockopt(_socketFD, SOL_SOCKET, SO_REUSEADDR, &reuseaddr_on, sizeof(reuseaddr_on));
+ int one = 1;
+ if (setsockopt(_socketFD, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one)) != 0) {
+ throw std::runtime_error(std::string("setsockopt: ") + strerror(errno));
+ }
+#ifndef _WIN32
int flags = fcntl(_socketFD, F_GETFL);
if (flags >= 0) {
flags |= O_NONBLOCK;
if (fcntl(_socketFD, F_SETFL, flags) < 0) {
- // could not set to non-blocj
+ // could not set to non-block
}
}
+#else
+ unsigned long on = 1;
+ if (ioctlsocket(_socketFD, FIONBIO, &on) != 0) {
+ // could not set to non-block
+ }
+#endif
_listenerEvent = event_new(_base->base, _socketFD, EV_READ|EV_PERSIST, acceptCallback, (void*)this);
/*XXX check it */
@@ -353,13 +355,24 @@ void ServerSocket::Connection::reply(const char* data, size_t size) {
bufferevent_write(bufferEvent, data, size);
}
+PacketServerSocket::~PacketServerSocket() {
+ for(std::map<Connection, std::stringstream*>::iterator fragIter = _fragments.begin();
+ fragIter != _fragments.end();
+ fragIter++) {
+ delete fragIter->second;
+ }
+}
+
void PacketServerSocket::readCallback(const char* data, size_t size, Connection& conn) {
- std::stringstream& fragment = _fragments[conn];
- fragment << std::string(data, size);
+ if (_fragments.find(conn) == _fragments.end())
+ _fragments[conn] = new std::stringstream();
+
+ std::stringstream* fragment = _fragments[conn];
+ *fragment << std::string(data, size);
size_t startPos = 0;
size_t endPos;
- const std::string& buffer = fragment.str();
+ const std::string& buffer = fragment->str();
while((endPos = buffer.find(_sep, startPos)) != std::string::npos) {
// std::cout << ">" << buffer.substr(startPos, endPos - startPos) << "<" << std::endl;
readCallback(buffer.substr(startPos, endPos - startPos), conn);
@@ -367,9 +380,9 @@ void PacketServerSocket::readCallback(const char* data, size_t size, Connection&
}
if (startPos != 0 && startPos < buffer.size() + 1) {
std::string rest = buffer.substr(startPos);
- fragment.str(std::string());
- fragment.clear();
- fragment << rest;
+ fragment->str(std::string());
+ fragment->clear();
+ *fragment << rest;
}
}
diff --git a/src/uscxml/server/Socket.h b/src/uscxml/server/Socket.h
index 9330c4b..7bb8ebe 100644
--- a/src/uscxml/server/Socket.h
+++ b/src/uscxml/server/Socket.h
@@ -103,14 +103,14 @@ protected:
class USCXML_API PacketServerSocket : public ServerSocket {
public:
PacketServerSocket(int domain, int type, int protocol, const std::string& sep) : ServerSocket(domain, type, protocol), _sep(sep) {}
- virtual ~PacketServerSocket() {}
+ virtual ~PacketServerSocket();
void readCallback(const char* data, size_t size, Connection& conn);
virtual void readCallback(const std::string& packet, Connection& conn) = 0;
protected:
std::string _sep;
- std::map<Connection, std::stringstream> _fragments;
+ std::map<Connection, std::stringstream*> _fragments;
};
class USCXML_API ClientSocket : public Socket {