I'm trying to use SocketBase::Unread for testing purposes. What I do is read the data from the socket via wxSocketClient and then unread it so it can be read again. The trouble is, it will only unread if my buffer is less than what is going to be read. For this test I expect 51 bytes, but if my buffer is 51, then Unread fails to work. I set it to 50 and it works, but obviously it chops off a byte. I don't set any socket flags so it will default to wxSOCKET_NONE.
Code: Select all
char* Unreadtest::inputTest_ = new char[100];
void Unreadtest::OnSocketEvent(wxSocketEvent &event)
{
int len = 50; //reading 51 causes unread to fail
int num =0;
std::cout << "UnreadTest: OnSocketEvent\n";
switch(event.GetSocketEvent())
{
case wxSOCKET_INPUT:
{
server_->Read(inputTest_,len);
num = server_->LastCount();
server_->Unread(inputTest_,num);
inputTest_[len] = '\0';
break;
}
default: break;
}
std::cout << "\nUnreadTest: buffer length is " << len << "\n";
std::cout << "\nUnreadTest: read num length is " << num << "\n";
std::cout << "\nUnreadTest: Read " << inputTest_ << "\n";
loop.Exit();
}
UnreadTest OnServer Event Fired
UnreadTest: wxSOCKET_CONNECTION
UnreadTest: OnSocketEvent
UnreadTest: buffer length is 51
UnreadTest: read num length is 51
UnreadTest: Read 200 123-PC TEST1 Version 1.1b1,, S0, posting OK
The output for len=50 is:
UnreadTest OnServer Event Fired
UnreadTest: wxSOCKET_CONNECTION
UnreadTest: OnSocketEvent
UnreadTest: buffer length is 50
UnreadTest: read num length is 50
UnreadTest: Read 200 123-PC TEST1 Version 5.7b1,, S0, posting OK
UnreadTest: OnSocketEvent
UnreadTest: buffer length is 50
UnreadTest: read num length is 50
UnreadTest: Read 200 123-PC TEST1 Version 5.7b1,, S0, posting OK
So, I'm wondering why that is? Although I know it is 51 bytes for this test, I won't know what length the input will be exactly each time, so it is a problem.
Cheers,
Zobbo