|
View previous topic :: View next topic |
Author |
CRC Checksums and Time-outs sample code won't compile or run |
Cuchulainn
Joined: 18 Dec 2006
Posts: 593
Location: Amsterdam, the Netherlands
|
Posted: Thu Mar 07, 2013 11:26 pm Post subject: |
|
|
Thanks for the detailed answer, Robert.
Compiler differences it looks like? OP can now try this out.
Daniel |
|
Back to top |
|
|
robert2098
Joined: 27 Dec 2007
Posts: 2
|
Posted: Thu Mar 07, 2013 10:17 pm Post subject: Re: CRC Checksums and Time-outs sample code won't compile or |
|
|
Hi abl,
Thanks for reporting the problem.
abl wrote: |
Beep() is a Windows function, but I'm running on Linux. I know how to make noise on Linux with echo, but I don't need that to see the program work. I comment out the lines with Beep() in them:
|
Yes, the Beep function is a Windows function and is used so you can hear that a keep alive is received. You can safely comment it out.
abl wrote: |
The compiler can't find toupper. That is not a problem because I can live without a translation to upper case as evidence that a message reached the server.
|
Actually the problem is that the compiler finds two overloads of "toupper()". One in <locale> with two arguments and one in <cctype> with one argument. When passing the "toupper()" function (function pointer) as argument to the "transform()" function the GNU compiler can't deduct that the version with one argument is meant while the Visual C++ compiler can. The solution is to wrap the call to toupper() in another function that has no conflict.
Thus add the following code to the "Server.hpp" file in the ASyncConnectionMt class:
Code: |
// There are two toupper() functions, one in <locale> and one in <cctype>.
// When passing a pointer to the toupper() function to the std::transform() function,
// the GNU g++ compiler can't choose which function to take and gives a compiler error. Microsoft Visual C++ can take the right version.
// By wrapping it in another function
static char myToUpper(char c)
{
return std::toupper(c);
}
|
And replace the line with the "transform()" function with:
Code: |
std::transform(str.begin(), str.end(), str.begin(), &ASyncConnectionMt::myToUpper);
|
abl wrote: |
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
|
This is caused in how the GNU and Visual C++ compilers differ in handling the length of data types in 64bit code. With the transition to 64bit code Microsoft explicitly kept the length of integer data types the same for compatibility reasons. Thus under both 32 and 64 bit Visual C++ compilers and 32 bit GNU compiler the data type have the following lengths:
short = 16 bit
int = 32 bit
long = 32 bit
long long = 64 bit
But under Linux/GNU, the 64 bit compilers changed the length of data types to:
short = 16 bit
int = 32 bit
long = 64 bit
long long = 64 bit
This caused a problem in building the byte array from the message data for sending a message over the network because it assumed a long was 32 bit.
The solution is to find and replace all the "long"s in the "Message.hpp" file by 'int32_t' which is normally defined in <stdint.h> header file. But this header file is not included in Visual C++ 2008 and lower but luckily it is also defined in the boost libraries <boost/cstdint.hpp> so with boost applications it should also work under older Visual C++ version.
I hope I've answered your questions and that this solves your problems.
Regards,
Robert
|
|
Back to top |
|
|
Cuchulainn
Joined: 18 Dec 2006
Posts: 593
Location: Amsterdam, the Netherlands
|
Posted: Wed Mar 06, 2013 8:46 am Post subject: |
|
|
You're welcome. And thanks again for the feedback.
For Volume III (libs, design and applications) we will deliver the code for both linux and Windows. |
|
Back to top |
|
|
abl
Joined: 28 Feb 2013
Posts: 6
|
Posted: Tue Mar 05, 2013 4:10 pm Post subject: |
|
|
Quote: |
We ran the program on Windows and it works fine. Seems like a buffer problem you are experiencing. |
Of course, it ran fine under Windows! I wouldn't expect anything less.
That is what you wrote it for; is it not? :)
Try compiling, linking, and running it under any 64-bit Linux distribution with a recent version of Boost installed by hand instead using whatever old version the distribution's repository may have.
Quote: |
We'll get back on this issue. |
Thank you for the attention that you are giving to this matter.
|
|
Back to top |
|
|
Cuchulainn
Joined: 18 Dec 2006
Posts: 593
Location: Amsterdam, the Netherlands
|
Posted: Tue Mar 05, 2013 3:54 pm Post subject: |
|
|
We ran the program on Windows and it works fine. Seems like a buffer problem you are experiencing.
We'll get back on this issue. |
|
Back to top |
|
|
abl
Joined: 28 Feb 2013
Posts: 6
|
Posted: Mon Mar 04, 2013 8:59 pm Post subject: |
|
|
Quote: |
> We are not familar with, and do not support CentOS. |
As I wrote in my original post, CentOS is essentially RedHat -- with GNU g++ 4.4.6 20120305 (Red Hat 4.4.6-4).
CentOS is built from all the RedHat sources that are not proprietary to RedHat. Thus, CentOS provides the stability of RedHat without RedHat's fees.
If you support RedHat Linux, you already support CentOS.
Do you support RedHat Linux?
Do you support any Linux systems, or does your example code run only on Windows?
Quote: |
So my question does this boost library support the OS or is it an application error from the book? |
Boost.org's page http://www.boost.org/users/history/version_1_52_0.html lists only compilers under Linux not distributions of Linux. The answer to your question is yes my OS is supported under that version of Boost.
In that list, GCC 4.4.3 appears; because my compiler is GNU g++ 4.4.6 20120305 (Red Hat 4.4.6-4), I would say that my compiler is also supported by that version of Boost.
It's not the library, not the OS, not the compiler: There is a bug in the example program.
It is clear from its reliance on a Windows only function, Beep(), that it has been compiled, linked, and run only on Windows, but as my original post makes clear, the problems go beyond merely that.
Quote: |
Can you run it under Windows as well? |
No, I haven't tried because I haven't had a copy of Windows since 1986. It was a less than useful Windows 2 as I recall.
Quote: |
If it is giving problems we will fix it. |
It is clearly not being compiled, linked, or running at all.
I would describe that as giving problems.
Please, fix it.
|
|
Back to top |
|
|
Cuchulainn
Joined: 18 Dec 2006
Posts: 593
Location: Amsterdam, the Netherlands
|
Posted: Mon Mar 04, 2013 2:51 pm Post subject: |
|
|
We are not familar with, and do not support CentOS. So my question does this boost library support the OS or is it an application error from the book?
Can you run it under Windows as well? If it is giving problems we will fix it. |
|
Back to top |
|
|
abl
Joined: 28 Feb 2013
Posts: 6
|
Posted: Thu Feb 28, 2013 8:50 pm Post subject: CRC Checksums and Time-outs sample code won't compile or run |
|
|
The sample code from book 2, chapter 10, section 6, CRC Checksums and Time-outs fails to compile or even run under CentOS release 6.3 (Final) -- CentOS is essentially RedHat -- with GNU g++ 4.4.6 20120305 (Red Hat 4.4.6-4) and with BOOST_VERSION 105200 and BOOST_LIB_VERSION "1_52" from Boost version.hpp:
Code: |
[user@host current_pathname]$ g++ -g -I. -I/usr/local/include -I/usr/local/include/boost -L/usr/local/lib -lboost_locale -lboost_thread Main.cpp
In file included from Main.cpp:15:
Client.hpp: In member function void Client::HandleReadHeader(Client::MessagePtr, const boost::system::error_code&):
Client.hpp:211: error: Beep was not declared in this scope
In file included from Main.cpp:15:
Client.hpp: In member function void Client::StartSendHeartbeat():
Client.hpp:348: error: Beep was not declared in this scope
In file included from Main.cpp:16:
Server.hpp: In member function void ASyncConnectionMt::HandleReadBody(ASyncConnectionMt::MessagePtr, const boost::system::error_code&):
Server.hpp:192: error: no matching function for call to transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded function type>)
[user@host current_pathname]$ |
Beep() is a Windows function, but I'm running on Linux. I know how to make noise on Linux with echo, but I don't need that to see the program work. I comment out the lines with Beep() in them:
Code: |
[user@host current_pathname]$ grep -n Beep *.[ch]pp
Client.hpp:211: Beep(1400, 200);
Client.hpp:348: Beep(700, 200);
[user@host current_pathname]$ |
and recompile:
Code: |
[user@host current_pathname]$ g++ -g -I. -I/usr/local/include -I/usr/local/include/boost -L/usr/local/lib -lboost_locale -lboost_thread Main.cpp
In file included from Main.cpp:16:
Server.hpp: In member function void ASyncConnectionMt::HandleReadBody(ASyncConnectionMt::MessagePtr, const boost::system::error_code&):
Server.hpp:192: error: no matching function for call to transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded function type>)
[user@host current_pathname]$ |
The compiler can't find toupper. That is not a problem because I can live without a translation to upper case as evidence that a message reached the server. I comment out that line, and the compiler runs error free and links a binary.
I run the binary and type 2 to get the server running:
Code: |
[user@host current_pathname]$ a.out
TCP networking example.
Debugging commands after connecting:
- ClientHeartbeatOn
- ServerHeartbeatOn
- ClientHeartbeatOff
- ServerHeartbeatOff
- ClientSendCrcError
- ServerSendCrcError
1. Client
2. Server
Choice: 2
(thread id: 7f8a09f3e720) Listening to TCP socket on port 60000... |
That is excellent! Encouraged, I start the client and watch it fail:
Code: |
[user@host current_pathname]$ a.out
TCP networking example.
Debugging commands after connecting:
- ClientHeartbeatOn
- ServerHeartbeatOn
- ClientHeartbeatOff
- ServerHeartbeatOff
- ClientSendCrcError
- ServerSendCrcError
1. Client
2. Server
Choice: 1
Enter the host to connect to (empty=localhost):
Debugging commands:
- ClientHeartbeatOff
- ClientHeartbeatOn
- ServerHeartbeatOff
- ServerHeartbeatOn
- ClientSendCrcError
- ServerSendCrcError
Connecting to 127.0.0.1:60000...
Connected to 127.0.0.1:60000
Enter text to send:
1234
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
Aborted
[user@host current_pathname]$ |
Longer text or one of the commands elicits a different error:
Code: |
[user@host current_pathname]$ a.out
TCP networking example.
Debugging commands after connecting:
- ClientHeartbeatOn
- ServerHeartbeatOn
- ClientHeartbeatOff
- ServerHeartbeatOff
- ClientSendCrcError
- ServerSendCrcError
1. Client
2. Server
Choice: 1
Enter the host to connect to (empty=localhost):
Debugging commands:
- ClientHeartbeatOff
- ClientHeartbeatOn
- ServerHeartbeatOff
- ServerHeartbeatOn
- ClientSendCrcError
- ServerSendCrcError
Connecting to 127.0.0.1:60000...
Connected to 127.0.0.1:60000
Enter text to send:
ServerHeartbeatOff
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted
[user@host current_pathname]$ |
Please post a working copy of that sample program.
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|