Uh oh!
There was an error while loading. Please reload this page.
reduced to 2 classes: PassiveSocket and SimpleSocket .. and some more fixes/additions - #4
reduced to 2 classes: PassiveSocket and SimpleSocket .. and some more fixes/additions#4hayguen wants to merge 19 commits into
Conversation
lethosor
commented
Jun 17, 2016
Does this maintain source compatibility (i.e. is it possible to still use CActiveSocket)? |
hayguen
commented
Jun 17, 2016
hmmm, you are right, my patch breaks compatibility! |
hayguen
commented
Jun 17, 2016
in the examples it fixed that problem. |
hayguen
commented
Jun 19, 2016
my last commit with new examples and many new aliases (inline functions) and a few bugfixes were merged into this pull request .. |
warmist
commented
Jun 20, 2016
Have you tried building dfhack with it? |
hayguen
commented
Jun 20, 2016
Nope. I'm using clsocket for extio_rtl_tcp There shouldn't be errors building DFHack .. are there? |
warmist
commented
Jun 20, 2016
oh my bad. Thought that this is not used anywhere else. |
hayguen
commented
Jun 20, 2016
Had found clsockets few years ago. Think, it was at the authors official site, which now is down
Had used multicast UDP sockets at that time ... You see any problem using DFHack/clsocket as "base" for further developments? |
warmist
commented
Jun 20, 2016
Nope. Just thought that something more popular exists and we're just using this mostly because it's very simple and we started using it. |
hayguen
commented
Jun 20, 2016
There's nothing wrong, when it's simple! |
| CSimpleSocket::Send(pBuf, bytesToSend); | ||
| break; | ||
| case CSimpleSocket::SocketTypeInvalid: | ||
| case CSimpleSocket::SocketTypeTcp6: |
There was a problem hiding this comment.
Should Tcp6 be here or part of the previous case for Tcp?
hayguen
commented
Jul 8, 2016
you are definitely right: that code looks wrong. noticed that also. |
hayguen
commented
Jul 21, 2016
Found out, that there's much more to do, besides the correct switch case, that IPv6 works correctly: |
Do we really need From here:
And here:
Basically, if you care about receiving the same number of bytes that were sent, you should probably include the message length in the message, instead of relying on the network to transmit the entire message at once. I'll still see if I can fix it on OS X if it is needed, but I'm not sure about it. This is the patch I made to get it to compile, by the way: diff --git a/src/SimpleSocket.cpp b/src/SimpleSocket.cpp
index 2d0eedd..4c613f9 100644
--- a/src/SimpleSocket.cpp+++ b/src/SimpleSocket.cpp@@ -42,7 +42,7 @@
*----------------------------------------------------------------------------*/
#include "SimpleSocket.h"
-#ifdef _LINUX+#if defined(_LINUX) || defined(_DARWIN)
#include <sys/ioctl.h>
#endif
#include <string.h>
@@ -1326,7 +1326,7 @@ int32 CSimpleSocket::GetNumReceivableBytes()
return -1;
return (int32)numBytesInSocket;
-#elif defined(_LINUX)+#elif defined(_LINUX) || defined(_DARWIN)
int32 numBytesInSocket = 0;
if ( ioctl(m_socket, FIONREAD, (char*)&numBytesInSocket) < 0 )
return -1; |
hayguen
commented
Aug 8, 2016
I definitely need it in some other closed-source project, where i replaced the Qt4 Socket stuff. |
lethosor
commented
Aug 8, 2016
Just I think I found a way to get it working on OS X, though, if it's necessary. |
hayguen
commented
Aug 8, 2016
The company specific close source has its own abstraction for network/tcp connections, where Qt4 was utilized in the back end. Now, replaced that Qt4 - without touching the application layer / logic :-) |
lethosor
commented
Aug 8, 2016
Oh, so you're replacing Qt's equivalent of |
hayguen
commented
Aug 8, 2016
More or less: yes. |
ce59dda to
9527220Compare…hread, libstdc++, .. build examples also on mingw Signed-off-by: hayati ayguen <h_ayguen@web.de>
moved Open() and ConnectXX methods from ActiveSocket into SimpleSocket PassiveSocket now returns SimpleSocket at Accept() ActiveSocket got unnecessary .. but kept file for compatibility Signed-off-by: hayati ayguen <h_ayguen@web.de>
* added example DelayedEchoServer - sends back received data after some delay * added console/log output to EchoServer example * added example TxToServer - sends tcp data to echo server utilizes SetSendWindowSize() and fixed Select()/WaitUntilReadable() * added example UdpServer - prints received data to stderr * added example TxToUdpServer - sends udp data to udp server * added alias (inline) CPassiveSocket::Bind() for BindMulticast() without multicast group * fixed BindMulticast() for NULL ptr to mulicast group * added alias (inline) CSimpleSocket::ConnectTo() for Open() * added aliases CloseForXX() for Shutdown() variants * fixed SetReceiveTimeout() and SetSendTimeout() for Windows: Windows does not expect/support struct timeval - only milliseconds * added aliases SetReceiveTimeoutMillis() and SetSendTimeoutMillis() * added extra options bAwakeWhenReadable and bAwakeWhenWritable for Select(), both defaulting to true - as before, but usually not making much sense! * added aliases WaitUntilReadable() and WaitUntilWritable() with milliseconds * added aliases GetSocketErrorText() for DescribeError) * added alias Reveive() with 'char*' * added alias Send() with 'const char*' * added aliases Transmit() with 'const uint8*' and 'const char*' * renamed SetOptionLinger()'s nTime parameter to nTimeInSeconds Signed-off-by: hayati ayguen <h_ayguen@web.de>
Signed-off-by: hayati ayguen <h_ayguen@web.de>
hayguen
commented
Aug 12, 2020
i've moved and rebased (merged latest changes from here). |
lethosor
commented
Aug 12, 2020
I'm pretty sure #4 (comment) still needs to be addressed for macOS. |
added GetNumReceivableBytes() added IsServerSide() added Get(Peer/Local)(Addr/Port) allow examples to connect from remote computers this is for testing examples (server/client) on different OS/machines rebase amended bugfix patch from lethosor for DARWIN/OS X Signed-off-by: hayati ayguen <h_ayguen@web.de>
* SetConnectTimeoutMillis() was setting the receive timeout * optimization: CPassiveSocket::Accept() does now waits for result of accept() before creating CSimpleSocket() - that's interesting for a NonBlocking CPassiveSocket * added bool CSimpleSocket::IsSocketPeerClosed() returning if remote side closed the socket * made IsBlocking() const * added inlines for IsSocketPeerOpen(), IsSocketInvalid() and IsNonblocking() simplifying logic in if expressions * added internal PRINT_CLOSE macro for debugging Signed-off-by: hayati ayguen <h_ayguen@web.de>
problem scenario: when there's already an error outside the clsocket lib, then TranslateSocketError() could pick up the error, which was not caused by the clsocket-operation added ClearSystemError() and use it in some cases call/use TranslateSocketError() when necessary Signed-off-by: hayati ayguen <h_ayguen@web.de>
Signed-off-by: hayati ayguen <h_ayguen@web.de>
with kind permission of Procitec: * bugfixes in multicast UDP operation * enhancend for multithreaded use: - use GetAddrInfo[Static]() instead of deprecated GETHOSTBYNAME() - GetIPv4AddrInfoStatic() to allow address resolution without a connection instance * docs and other minor enhancements Signed-off-by: hayati ayguen <h_ayguen@web.de>
* mingw is missing inet_pton() function. - added replacement implementation - switched on with cmake option CLSOCKET_OWN_INET_PTON * msvc: static build against c runtime with cmake CLSOCKET_SHARED off * build examples with msvc - except clsocket-example requiring pthread Signed-off-by: hayati ayguen <h_ayguen@web.de>
* fixed CSimpleSocket::GetClientPort() * fixed peer/local address in CPassiveSocket::Accept() * fixed Linux compilation in CPassiveSocket::Listen() * added CSimpleSocket::Bind() for tcp/udp client connections * enhanced all examples: all print local/peer address and port * fixed output of GetLocalAddr() and GetPeerAddr() in examples * examples txtoserver and txtoudpserver with optional local binding Signed-off-by: hayati ayguen <h_ayguen@web.de>
* looks, some systems return random value! directly return 0 in this case Signed-off-by: hayati ayguen <h_ayguen@web.de>
yes, you were right. i rebase/amended your patch.
of course
sure, that's good .. especially after having all this stuff lying around for years |
lethosor
commented
Aug 12, 2020
I've been meaning to set up GitHub Actions in this repo - I was planning on just Linux (to replace Travis CI) but could probably add macOS and Windows too. That should help make sure it at least compiles on those platforms - not sure how comprehensive tests are currently. |
hayguen
commented
Aug 12, 2020
sounds great. i've no experience with this github actions kind of stuff ..
(nearly) all test programs are for manual execution .. but we should be able to figure out some automatic tests |
* renamed EXPORT to CLSOCKET_API, it's for export and import * added definition CLSOCKET_NO_EXPORT for not exporting private methods * cmake: export symbols only for shared library: EXPORT_CLSOCKET_SYMBOLS * have default visibility hidden - also on linux .. Signed-off-by: hayati ayguen <h_ayguen@web.de>
hayguen
commented
Aug 13, 2020
i'm not at work for the next 2 weeks from next monday .. but we have several more changes/commits, i'd need to merge .. |
Signed-off-by: hayati ayguen <h_ayguen@web.de>
Signed-off-by: hayati ayguen <h_ayguen@web.de>
…elect() Signed-off-by: hayati ayguen <h_ayguen@web.de>
Signed-off-by: Hayati Ayguen <h.ayguen@procitec.de>
Signed-off-by: Hayati Ayguen <h.ayguen@procitec.de>
see source!,
should be easier to use:
PassiveSocket for Server things
and SimpleSocket for everything else