Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'pauzowanie'

Conflicts:
	skunk_test.cpp

Wywalone trochę coutów
  • Loading branch information...
commit 9ea582aa55d03314349b8bb30b043bb73b2bda5a 2 parents 0b6f6fd + e816494
@tadzik authored
Showing with 27 additions and 9 deletions.
  1. +1 −1  Makefile
  2. +2 −0  Skunk.hpp
  3. +15 −6 csgi.cpp
  4. +4 −2 csgi.hpp
  5. +5 −0 skunk_test.cpp
View
2  Makefile
@@ -1,5 +1,5 @@
CXX?=clang++
-CFLAGS=-Wall -Wextra -pedantic -ggdb
+CFLAGS=-Wall -Wextra -pedantic -ggdb -std=c++0x
LDFLAGS=-lssl -lcrypto -lpthread
COMPILE= $(CXX) $(CFLAGS)
View
2  Skunk.hpp
@@ -243,6 +243,8 @@ class Server : CSGI::Application {
void run(bool);
CSGI::Response get(CSGI::Env&, std::string&);
virtual CSGI::Response operator()(CSGI::Env&);
+ void pause(){srv->pause();}
+ void unpause(){srv->unpause();}
};
}
View
21 csgi.cpp
@@ -8,7 +8,12 @@ void *run_thread(void *arg)
srv->serve();
return NULL;
}
-
+void CSGI::Server::pause(){
+ pthread_mutex_lock(&pause_);
+}
+void CSGI::Server::unpause(){
+ pthread_mutex_unlock(&pause_);
+}
void CSGI::Server::run(bool async)
{
int i;
@@ -74,19 +79,21 @@ void CSGI::Server::run(bool async)
*/
void CSGI::Server::serve()
{
- int newfd;
+ int newfd, err;
+ CSGI::Env env;
- for (;;) {
+ for (;;pthread_mutex_unlock(&pause_)) {
+ pthread_mutex_lock(&pause_);
if (stop_) {
//std::cerr << "serve() stopping" << std::endl;
return;
}
SSL *ssl = SSL_new(ssl_ctx_);
// so we check stop_
- if (!can_read(sockfd_)) continue;
+ if (!can_read(sockfd_))continue;
newfd = accept(sockfd_, 0, 0);
SSL_set_fd(ssl, newfd);
- int err = SSL_accept(ssl);
+ err = SSL_accept(ssl);
if (err != 1) {
std::string res;
res.append("HTTP/1.1 400 Bad Request\r\n\r\n");
@@ -97,7 +104,6 @@ void CSGI::Server::serve()
close(newfd);
continue;
}
- CSGI::Env env;
try {
env = parse_request(ssl);
} catch (CSGI::InvalidRequest&) {
@@ -106,10 +112,13 @@ void CSGI::Server::serve()
close(newfd);
continue;
}
+ {
Response resp = (*app_)(env);
send_response(resp, ssl);
close(newfd);
SSL_free(ssl);
+ }
+
}
}
View
6 csgi.hpp
@@ -90,7 +90,7 @@ class Server {
Server(Application * app, int port) : app_(app), port_(port)
{
backlog_ = 10;
-
+ pause_ = PTHREAD_MUTEX_INITIALIZER;
SSL_library_init();
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
@@ -136,6 +136,8 @@ class Server {
*/
void run(bool async);
void serve();
+ void pause();
+ void unpause();
private: // udokumentowane w csgi.cpp
Env parse_request(SSL*);
void send_response(Response&, SSL*);
@@ -145,7 +147,7 @@ class Server {
int port_;
int backlog_;
int stop_;
-
+ pthread_mutex_t pause_;
pthread_t *worker_;
SSL_METHOD *ssl_method_;
SSL_CTX *ssl_ctx_;
View
5 skunk_test.cpp
@@ -86,6 +86,11 @@ int main(void) {
for(;;){
sleep(10);
//pt1->blockWidget();
+ srv->pause();
+ std::cout<<"pause"<<std::endl;
+ sleep(5);
+ srv->unpause();
+ std::cout<<"unpause"<<std::endl;
std::cout << pt1->getValue() << std::endl;
tmp = pt1->getValue() + itoa(i++);
pt1->setValue(tmp);

0 comments on commit 9ea582a

Please sign in to comment.
Something went wrong with that request. Please try again.