Skip to content

Commit

Permalink
fixed the socket timeout and buffer stream
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg committed Mar 7, 2014
1 parent a726b7b commit 5304333
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions jce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jce::jce(std::string username,std::string password)
JceConnector = new sslsocket(dst_host, dst_port); //open a new ssl connection to jce
if (JceConnector->isCon())
{
puts("Connected");
this->username = username;
this->pass = password;
makeFirstVisit();
Expand Down Expand Up @@ -49,10 +48,13 @@ void jce::makeFirstVisit()
puts ("message has been sent");
std::vector<std::string> reciever;
JceConnector->recieve((reciever));
//foreach (auto i = reciever.begin(); i != reciever.end(); ++i)
for (std::vector<std::string>::iterator i = reciever.begin(); i != reciever.end(); ++i)
{
std::cout << *i;
//printing the html
}
puts("\nrecieved");
}

//prgname=LoginValidtion1&Arguments=-N302539556,-A,-N013145836517240,-A,-A
}
15 changes: 11 additions & 4 deletions socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ Socket::~Socket()

bool Socket::create()
{
struct timeval timeout;
timeout.tv_sec = socketTimeOut;
timeout.tv_usec = 0;

m_sock = socket ( AF_INET, SOCK_STREAM, 0 );
if ( ! is_valid() )
return false;
int on = 1;
if ( setsockopt ( m_sock, SOL_SOCKET, SO_REUSEADDR, ( const char* ) &on, sizeof ( on ) ) == -1 )
if (setsockopt (m_sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on,sizeof(on)) == FAIL )
return false;

if (setsockopt (m_sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout,sizeof(timeout)) == FAIL)
return false;

return true;

}
Expand Down Expand Up @@ -76,7 +84,6 @@ bool Socket::recv() const
char buf[buffsize];
std::string p;
p.clear();
//ZeroMemory(buf, buffsize);
bzero(buf, sizeof(buf));
int status;
std::cout << "recieving..." << std::endl;
Expand Down Expand Up @@ -147,7 +154,7 @@ void Socket::set_non_blocking ( const bool b )
int opts;

opts = fcntl ( m_sock,
F_GETFL );
F_GETFL );

if ( opts < 0 )
{
Expand All @@ -160,6 +167,6 @@ void Socket::set_non_blocking ( const bool b )
opts = ( opts & ~O_NONBLOCK );

fcntl ( m_sock,
F_SETFL,opts );
F_SETFL,opts );

}
2 changes: 1 addition & 1 deletion socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define Socket_H

#define FAIL -1

#define socketTimeOut 4
//sock headers
#include <sys/types.h>
#include <sys/socket.h>
Expand Down
2 changes: 1 addition & 1 deletion sslsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ bool sslsocket::recieve(std::vector<std::string> &strvec) const
strvec.push_back(msg);
bzero(buf, sizeof(buf));
}
printf("\n");
if (status == SSL_RECEIVED_SHUTDOWN) //probably got what we need
return true;

Expand Down Expand Up @@ -79,6 +78,7 @@ bool sslsocket::connectTo(std::string host, int port)
ERR_print_errors_fp(stderr);
return false;
}
SSL_do_handshake(ssl);
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion sslsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "openssl/ssl.h"
#include "openssl/err.h"

#define BUFFER_SIZE 8192
#define BUFFER_SIZE 8000


class sslsocket : protected Socket
{
Expand Down

0 comments on commit 5304333

Please sign in to comment.