Fix bug in the server where a wait request was incorrectly handled.

Change the assert macro on Windows to make it easier to debug.
Review URL: http://webrtc-codereview.appspot.com/212002

git-svn-id: http://webrtc.googlecode.com/svn/trunk@718 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tommi@webrtc.org 2011-10-10 09:51:52 +00:00
parent c0b2250b20
commit f7b36a47c0
5 changed files with 33 additions and 13 deletions

View File

@ -10,7 +10,6 @@
#include "peerconnection/samples/server/data_socket.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View File

@ -8,7 +8,6 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -96,7 +95,7 @@ int main(int argc, char** argv) {
s->Send("500 Error", true, "text/plain", "",
"Peer most likely gone.");
}
} else if (member->is_waiting_socket(s)) {
} else if (member->is_wait_request(s)) {
// no need to do anything.
socket_done = false;
} else {

View File

@ -10,7 +10,6 @@
#include "peerconnection/samples/server/peer_channel.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -33,6 +32,16 @@
// at this point it is not working correctly in some popular browsers.
static const char kPeerIdHeader[] = "Pragma: ";
static const char* kRequestPaths[] = {
"/wait", "/sign_out", "/message",
};
enum RequestPathIndex {
kWait,
kSignOut,
kMessage,
};
//
// ChannelMember
//
@ -54,6 +63,10 @@ ChannelMember::ChannelMember(DataSocket* socket)
ChannelMember::~ChannelMember() {
}
bool ChannelMember::is_wait_request(DataSocket* ds) const {
return ds && ds->PathEquals(kRequestPaths[kWait]);
}
bool ChannelMember::TimedOut() {
return waiting_socket_ == NULL && (time(NULL) - timestamp_) > 30;
}
@ -157,16 +170,13 @@ ChannelMember* PeerChannel::Lookup(DataSocket* ds) const {
if (ds->method() != DataSocket::GET && ds->method() != DataSocket::POST)
return NULL;
static const char* kRequests[] = {
"/wait", "/sign_out", "/message",
};
size_t i = 0;
for (; i < ARRAYSIZE(kRequests); ++i) {
if (ds->PathEquals(kRequests[i]))
for (; i < ARRAYSIZE(kRequestPaths); ++i) {
if (ds->PathEquals(kRequestPaths[i]))
break;
}
if (i == ARRAYSIZE(kRequests))
if (i == ARRAYSIZE(kRequestPaths))
return NULL;
std::string args(ds->request_arguments());
@ -179,9 +189,9 @@ ChannelMember* PeerChannel::Lookup(DataSocket* ds) const {
Members::const_iterator iter = members_.begin();
for (; iter != members_.end(); ++iter) {
if (id == (*iter)->id()) {
if (i == 0) // wait
if (i == kWait)
(*iter)->SetWaitingSocket(ds);
if (i == 1) // sign_out
if (i == kSignOut)
(*iter)->set_disconnected();
return *iter;
}

View File

@ -29,7 +29,7 @@ class ChannelMember {
bool connected() const { return connected_; }
int id() const { return id_; }
void set_disconnected() { connected_ = false; }
bool is_waiting_socket(DataSocket* ds) const { return waiting_socket_ == ds; }
bool is_wait_request(DataSocket* ds) const;
const std::string& name() const { return name_; }
bool TimedOut();

View File

@ -11,6 +11,18 @@
#define PEERCONNECTION_SAMPLES_SERVER_UTILS_H_
#pragma once
#ifndef assert
#ifndef WIN32
#include <assert.h>
#else
#ifndef NDEBUG
#define assert(expr) ((void)((expr) ? true : __debugbreak()))
#else
#define assert(expr) ((void)0)
#endif // NDEBUG
#endif // WIN32
#endif // assert
#include <string>
#ifndef ARRAYSIZE