-/* $Id$
-
-This file is part of libmsphttp
-Copyright © 2008 Mikkosoft Productions, Mikko Rasa
-Distributed under the LGPL
-*/
-
#include <exception>
#include <msp/core/refptr.h>
#include <msp/net/inet.h>
+#include <msp/net/resolve.h>
#include <msp/net/streamsocket.h>
+#include <msp/strings/format.h>
#include "request.h"
#include "response.h"
#include "server.h"
event_disp(0)
{
sock.signal_data_available.connect(sigc::mem_fun(this, &Server::data_available));
- sock.listen(Net::InetAddr(0, port), 8);
+ RefPtr<Net::SockAddr> addr = Net::resolve("*", format("%d", port));
+ sock.listen(*addr, 8);
}
unsigned Server::get_port() const
if(cl.async)
{
cl.sock->write(resp.str());
- cl.sock->close();
cl.stale = true;
}
}
if(cl.request->get_method()!="GET" && cl.request->get_method()!="POST")
{
response = new Response(NOT_IMPLEMENTED);
- response->add_content("Method not implemented");
+ response->add_content("Method not implemented\n");
}
}
catch(const exception &e)
if(response->get_status()==NONE)
{
response = new Response(NOT_FOUND);
- response->add_content("The requested resource was not found");
+ response->add_content("The requested resource was not found\n");
}
}
}
if(response)
{
cl.sock->write(response->str());
- cl.sock->close();
cl.stale = true;
}
}
if(i->response==&resp)
return *i;
- throw InvalidParameterValue("Response does not belong to any client");
+ // XXX Do this differently
+ throw invalid_argument("Response does not belong to any client");
}