Skip to content

Commit

Permalink
Fixed several bugs
Browse files Browse the repository at this point in the history
1. MySocket.cpp readPublicKey() should close file when error happens.

2. SSL blocks sometimes for Opera only, that's annoying. Solved by
using setsockopt() to limit idle for 3 seconds.

Added readKey() in main.cpp, to optimize for file operations.
  • Loading branch information
lava committed Feb 14, 2012
1 parent fc03cb9 commit 8f565b1
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
** Science The University of Illinois at Urbana-Champaign
** http://www.cs.uiuc.edu/homes/kingst/Research.html
**
** Copyright (C) Sam King
** Copyright (C) Sam King and Hui Xue
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the
Expand Down Expand Up @@ -91,7 +91,7 @@ MySocket *Cache::getReplySocket(string host, bool isSSL, int serverPort)
return replySock;
}

//XXX: should check url, method, cookie, possible even port
//XXX: should check url, method, cookie, possible even port, like what we did in Java version
CacheEntry *Cache::find(string url, string /*request*/) {
map<string, CacheEntry *>::iterator i = m_store.find(url);
if(i == m_store.end())
Expand All @@ -107,7 +107,7 @@ void Cache::addToStore(string url, CacheEntry *ent) {

static void dbg_print_vector(CacheEntry *ent, string url, int browserId, string msg) {
vector<int> v = ent->getReqVec();
printf("%d: %d %d %d %s: %s\n", browserId, v[0], v[1], v[2], url.c_str(), msg.c_str());
cache_dbg("%d: %d %d %d %s: %s\n", browserId, v[0], v[1], v[2], url.c_str(), msg.c_str());
}


Expand Down Expand Up @@ -252,16 +252,16 @@ int Cache::fetch(CacheEntry *ent, string host, bool isSSL, int browserId, MySock
delete replySock;
return -1;
}
printf("%d FETCH CALLED %s, response length: %d\n", browserId, ent->getUrl().c_str(), ent->getResponse().length());
cache_dbg("%d FETCH CALLED %s, response length: %d\n", browserId, ent->getUrl().c_str(), ent->getResponse().length());
unsigned char buf[1024];
int num_bytes;
while((num_bytes = replySock->read(buf, sizeof(buf))) > 0) {
cerr << "read " << num_bytes << " from " << browserId << ent->getUrl().c_str() << endl;
//cerr << "read " << num_bytes << " from " << browserId << ent->getUrl().c_str() << endl;
ent->appendResponse((const char *)buf, num_bytes);
}
dbg_fetch(num_bytes);

printf("%d FETCHED %s, response length: %d\n", browserId, ent->getUrl().c_str(), ent->getResponse().length());
cache_dbg("%d FETCHED %s, response length: %d\n", browserId, ent->getUrl().c_str(), ent->getResponse().length());
delete replySock;
return 0;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ void Cache::getHTTPResponseNoVote(string host, string request, string url, int s
MySocket *browserSock, bool isSSL, MySocket *replySock)
{
if(replySock == NULL) {
cout << "get...NoVote(): replySock is NULL, give browser 404" << endl;
cerr << "get...NoVote(): replySock is NULL, give browser 404" << endl;
browserSock->write_bytes(reply404);
return;
}
Expand Down
44 changes: 44 additions & 0 deletions CacheEntry.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
/*========================================================
** University of Illinois/NCSA
** Open Source License
**
** Copyright (C) 2011,The Board of Trustees of the University of
** Illinois. All rights reserved.
**
** Developed by:
**
** Research Group of Professor Sam King in the Department of Computer
** Science The University of Illinois at Urbana-Champaign
** http://www.cs.uiuc.edu/homes/kingst/Research.html
**
** Copyright (C) Hui Xue
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the
** Software), to deal with the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimers.
**
** Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimers in the
** documentation and/or other materials provided with the distribution.
** Neither the names of Sam King or the University of Illinois,
** nor the names of its contributors may be used to endorse or promote
** products derived from this Software without specific prior written
** permission.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
** ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**==========================================================
*/

#include "CacheEntry.h"

CacheEntry::CacheEntry(int num_browsers, std::string _url, std::string _request)
Expand Down
2 changes: 1 addition & 1 deletion MySocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
** Science The University of Illinois at Urbana-Champaign
** http://www.cs.uiuc.edu/homes/kingst/Research.html
**
** Copyright (C) Sam King
** Copyright (C) Sam King and Hui Xue
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the
Expand Down
44 changes: 44 additions & 0 deletions UI.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
/*========================================================
** University of Illinois/NCSA
** Open Source License
**
** Copyright (C) 2011,The Board of Trustees of the University of
** Illinois. All rights reserved.
**
** Developed by:
**
** Research Group of Professor Sam King in the Department of Computer
** Science The University of Illinois at Urbana-Champaign
** http://www.cs.uiuc.edu/homes/kingst/Research.html
**
** Copyright (C) Hui Xue
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the
** Software), to deal with the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimers.
**
** Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimers in the
** documentation and/or other materials provided with the distribution.
** Neither the names of Sam King or the University of Illinois,
** nor the names of its contributors may be used to endorse or promote
** products derived from this Software without specific prior written
** permission.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
** ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**==========================================================
*/

#include "UI.h"
#include <iostream>
#include "unistd.h"
Expand Down
44 changes: 44 additions & 0 deletions UIQueueEntry.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
/*========================================================
** University of Illinois/NCSA
** Open Source License
**
** Copyright (C) 2011,The Board of Trustees of the University of
** Illinois. All rights reserved.
**
** Developed by:
**
** Research Group of Professor Sam King in the Department of Computer
** Science The University of Illinois at Urbana-Champaign
** http://www.cs.uiuc.edu/homes/kingst/Research.html
**
** Copyright (C) Hui Xue
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the
** Software), to deal with the Software without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Software, and to
** permit persons to whom the Software is furnished to do so, subject to
** the following conditions:
**
** Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimers.
**
** Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimers in the
** documentation and/or other materials provided with the distribution.
** Neither the names of Sam King or the University of Illinois,
** nor the names of its contributors may be used to endorse or promote
** products derived from this Software without specific prior written
** permission.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
** ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**==========================================================
*/

#include "UIQueueEntry.h"
#include "UI.h"

Expand Down
2 changes: 1 addition & 1 deletion dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define ui_dbg(...);

#define cache_dbg(...) do{printf(__VA_ARGS__);}while(0);
//#define cache_dbg(...) do{printf(__VA_ARGS__);}while(0);

//#define httpreq_dbg(...) do{printf(__VA_ARGS__);}while(0);

Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
** Science The University of Illinois at Urbana-Champaign
** http://www.cs.uiuc.edu/homes/kingst/Research.html
**
** Copyright (C) Sam King
** Copyright (C) Sam King and Hui Xue
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the
Expand Down

0 comments on commit 8f565b1

Please sign in to comment.