Fixing sockets and response.

This commit is contained in:
Ben Vanik 2013-12-21 11:52:48 -08:00
parent d98d5c855a
commit da340891c4
3 changed files with 27 additions and 20 deletions

View File

@ -35,6 +35,15 @@ socket_t xe_socket_create_tcp() {
}
void xe_socket_close(socket_t socket) {
struct linger so_linger;
so_linger.l_onoff = TRUE;
so_linger.l_linger = 30;
setsockopt(
socket,
SOL_SOCKET,
SO_LINGER,
(const char*)&so_linger,
sizeof so_linger);
shutdown(socket, SD_SEND);
closesocket(socket);
}

View File

@ -223,34 +223,28 @@ int WSClient::PerformHandshake() {
xesnprintfa(title_id, XECOUNT(title_id), "%.8X",
header->execution_info.title_id);
ostringstream response;
ostringstream response_body;
if (module) {
response <<
"HTTP/1.0 200 OK\r\n"
"Content-Type: application/json\r\n"
"Connection: close\r\n"
"\r\n";
response << "[{";
response <<
response_body << "[{";
response_body <<
"\"name\": \"" << module->name() << "\",";
response <<
"\"path\": \"" << module->path() << "\",";
response <<
response_body <<
"\"titleId\": \"" << title_id << "\"";
response << "}]";
response <<
"\r\n"
"\r\n";
response_body << "}]";
} else {
response <<
response_body <<
"[]";
}
size_t content_length = response_body.str().length();
ostringstream response;
response <<
"HTTP/1.0 200 OK\r\n"
"Content-Type: application/json\r\n"
"Connection: close\r\n"
"\r\n"
"[]"
"\r\n"
"Access-Control-Allow-Origin: *\r\n"
"Content-Length: " << content_length << "\r\n"
"\r\n";
}
response << response_body.str();
error_code = WriteResponse(response.str());
if (error_code) {
return error_code;

View File

@ -35,6 +35,10 @@ XModule::XModule(KernelState* kernel_state, const char* path) :
if (slash) {
XEIGNORE(xestrcpya(name_, XECOUNT(name_), slash + 1));
}
char* dot = xestrrchra(name_, '.');
if (dot) {
*dot = 0;
}
}
XModule::~XModule() {