Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - zac

Pages: [1] 2
1
Network / Massive Memory Leak
« on: February 03, 2009, 03:42:29 pm »
There is a leak in heap memory, either in the classes Http or in one of the underlying classes. I am not using new or delete (despite for one single new/delete on begin/end of the program) in my program (downloading musics from lastfm), but it starts to use more and more heap space (memory field is heap). After ~200 MB of transferred data it uses ~40 MB ram (it begins with 2,2 MB)...
But I can't see where in the Http class it could be -.- all you use are C++-STL classes, I think.
I'll recheck my own code again and see if I can find a reason in there...

Ah:
I think I see now, it has most propably to do with the system cleaning up the memory allocated for the sockets or something similar, because the memory usage drops all of a shudden after reaching a high level (~50 MB) back down to ~6 MB. Seems very strange to me.

2
Feature requests / "GetConnectedAddress" function for SocketTCP
« on: January 21, 2009, 02:41:44 pm »
If connected, the function returns the IP address of the foreign host. If not, the returned IP is invalid. I know this can also be done by saving the IP of the foreign host on connection, but this can get quite hard - for example if you have an own (in my case cryptographic) session management in your server and don't have to (and don't want to) rely on a constant IP address for a client. The clients and the server are not keeping the connections alive - this is not possible for a server with possibly more than 1000 clients. You'll get in trouble updating the IP, make your storage for ips thread-safe and so on...

Code: [Select]


sf::IPAddress SocketTCP::GetConnectedAddress() const
{
if(IsValid())
{
sockaddr_in ipbuffer;
SocketHelper::LengthType len = static_cast<SocketHelper::LengthType>(sizeof(ipbuffer));

if(getpeername(mySocket,reinterpret_cast<sockaddr*>(&ipbuffer),&len) == 0)
return IPAddress(inet_ntoa(ipbuffer.sin_addr));
}
return IPAddress();
}


3
Network / Just another funny bug
« on: January 20, 2009, 06:48:01 pm »
Hey - I seem to be receiving a SIGPIPE from within SocketTCP::Send - it means that you try to write to a socket without a reader - the default reaction is to terminate the application.
This is what happens to my server if the client kills the connection before everything is ready. At first, a FIN packet is sent, but the server does not react to it properly. Then, when the server is trying to write again (because Send did not return Socket::Error but Socket::NotReady from within Send), it really sends the data (normal PSH packet), but all it gets is the RST packet from the obviously already closed client socket.
And then, the server process receives a "SIGPIPE" signal and is terminating.

I'm working with Non-Blocking sockets.

A possible workaround:
Add "signal(SIGPIPE,SIG_IGN);" to the SocketHelper initialisation for Linux.
I would also suggest to test the return value when you are sending the packet size in SocketTCP::Send(const sf::Packet&).

4
Network / Alternative to whatismyip.org
« on: January 18, 2009, 03:55:06 pm »
Looking for an alternative to whatismyip.org (which is not reachable, at least from here)...
Code: [Select]

     sf::IPAddress __getIpFromCheckipdyndns_org()
    {
IPAddress PublicAddress;

Http Server("http://checkip.dyndns.org");
Http::Request Request(Http::Request::Get, "/");
Http::Response Page = Server.SendRequest(Request,4.f);

if(Page.GetStatus() == Http::Response::Ok)
{
string s = Page.GetBody();
size_t ind = s.find_first_of("0123456789");
if(ind != string::npos)
{
size_t indl = s.find_first_not_of("0123456789.",ind);
string sub = s.substr(ind,indl-ind);
if(sub.length() >= 7 && sub.length() <= 15)
{
PublicAddress = sub;
}
}
}
return PublicAddress;
}


Any idea why it is not working (the page is reachable in my Browser), but immediately returning an empty page??

5
Feature requests / Add Timeout to "GetPublicAddress"
« on: January 18, 2009, 01:22:45 am »
Problem:
The server at whatismyip.org is sometimes not responsive or does not answer our requests (for unknown reasons, though I only do a request once, when (re)starting the program).

Possible solution/workaround:
Add a way to pass a timeout value. If the connection to the server can not be created successfully, return an invalid IP.

Since you are using the HTTP class to connect by now, I would suggest to add a timeout in the HTTP/FTP class too. It is supported by the underlying sockets, so it shouldn't be to hard to implement...

6
Network / Remove Output Messages?
« on: January 16, 2009, 06:20:27 pm »
I'm quite annoyed by SFMLs messages on failed Connections or on failure to close sockets.
I don't think it is the work of a portable library to warn the user about such things, for he should not be interested in them - and especially for the network, there are many reasons for a Socket failing to close or to accept an incoming connection, not always assoziated with the work of the programmer. Furthermore, the warnings can not be internationalized - there are a lot of reasons for not using the console output (especially for the network classes, warnings on missing images for example are okay). You might deactivate them for example when NDEBUG is defined.

7
Network / Packet Send - Fragmentation?
« on: December 10, 2008, 01:04:56 am »
I have a little question here:
Does the SocketTCP make sure that what the client is sending as ONE packet can be received by the server also using SocketTCP as ONE packet? Or do you have to use packet length values? (huge difficulties and potentially dangerous possibilities of programming errors (e.g. allowing Exploitation/Remote Code Injection, we all know Teardrop a.s.o. working with packet fragmentation; demonstrating that it may be a complex topic to handle fragmented packets) may arise - I would request a socket class automatically handling this issue.)

Then, if you have to do so, how do you measure the amount of data that is still left to read? Use Packet::GetDataLength()?
Does Receive() Append() or first Clear() and then Append() (last case would really be crappy)?

Will something like this do the trick (assuming the length value (packet length including the length value itself) is sent first - the whole thing is multithreaded and has to listen to a bool "running" value, so we can't use sf::Selector to do timeouts...):

Code: [Select]

sf::SocketTCP sock; //(this will be properly initialized)
sf::Packet p;
Uint32 length = 0;
sf::Clock clock;
sf::Socket::Status sstate;
sock.SetBlocking(false);

do
{
     sstate = sock.Receive(p);
     if(sstate == Socket::NotReady)
     {
           Sleep(0.05f);
           continue;
     }
     else if(sstate == Socket::Done)
     {
          if(!length) //we do not have a length value now
          {
               if(p.GetDataSize() > 4) //can we read 32 bit?
               {
                    p >> length; //will this decrease the "GetDataSize()" value by 4???????
               }
          }
          else
          {
                if(p.GetDataSize() < length)
                {
                       continue;
                }
                else if(p.GetDataSize() > length) throw 1; /*error - what happens with 2 packets sent with VERY low time gap? With packets send at the same time?*/
                else break; // we have collected all the data and nothing MORE
          }
     }
     else throw 1; //error
}
while(clock.GetElapsedTime() < 5.f); //Timeout



Packets coming fast one after the other could cause problems too - in fact, this should be very likely (would be treated as an error here, but that is some kind of really unwanted behaviour... So this causes even more pain, using serial numbers for each packet or likewise and treating the stuff read from a socket unwillingly... I would like to have a receive function giving me the power to say which amount of data I am requesting AND using sf::Packet. What if I use the Pointer/Length Receive function? Will the received data on the socket NOT fitting in the buffer given STAY there on the top of the socket?

I think this would be important to point out in the tuts...

8
System / Unicode class
« on: October 13, 2008, 12:29:56 am »
Could you add a function ToWstring?
I am asking this because wstring (std::string<wchar_t>) can be UTF16 (most 32 bit systems) or UTF32 (as with me, 64 bit system, where sizeof(wchar_t) == 4).
Would be convenient, but I can add these functions myself.

Which locale does the Unicode::Text-Class use?

9
System / Some simple questions about the Thread class
« on: October 10, 2008, 07:34:58 pm »
How is the thread class implemented in Linux?
Are they kernel threads (via clone() or sys_clone()?), or fibers?
Is SFML-Thread based on libraries like pethread or GNU-portable-threads?

10
Audio / Some weird audio problems
« on: October 10, 2008, 05:02:53 pm »
Now, I am encountering some further problems with the sf::Music class.
First, the Music clicks from time to time (I think when the buffer is reloaded) and is not fluent. Other music players did not have any problems with these files.
(No, this is not the clicking bug with the optimizations for ogg-Files, I encountered this problem too but setting optimization to -O instead of -O2 for std_vorbis.c fixed it)
The CPU power for playing Music is kind of extraordinary too (every 2 seconds, I think on reloading the buffer, it consumes up to 80%) for an ordinary 4 minute ogg music file with 128 bps.

The other problem is kind of weird:
Most sound files shorter than one buffer (I am taking 2*44100 samples as buffer for it reduces clicking noises) do not even work. They are loaded successfully (OpenFromFile returns true for this .wav-file), but Play simple does nothing, while longer music files work without any problems (except this clicking noise).
Do I have to build in another interface for playing sf::Sound's to fix this?
Because I wanted the soundfiles to be replacable without changing the code, I really dislike this idea... what if someone wants to exchange a little notification sound or the initialization sound of an application with some longer piece of music? This would, for sf::Sound, stay in memory until the application dies (I really need a call-and-forget interface for playing Music, so I am thinking about an own soundManager with its own thread, but this is surely a nice amount of work). And for the normal application state, it would consume even more CPU power and memory than the other solution...

Ah yes, and sometimes (somehow by random, but not very often) if the sound device is already opened by another player, my app gets a SIGSEGV signal from out of the "Play()" call.

Currently testing on the following system:
64 bit Ubuntu
AMD Athlon 64 3500+

11
Audio / Something about function names
« on: October 10, 2008, 12:08:53 am »
No, this is not another request about "How about obeying C++-naming-conventions", but I think it is rather annoying that the function for opening a music file is not named "OpenFromFile" (as in tutorial and documentation), but simply Music::Open... (even in the tutorial, it is also mentioned as Music::Open and Music::OpenFromFile, but the first one not very explicitely...)
How about changing docu/tuts?

12
General / Crashes when exiting?
« on: October 01, 2008, 11:12:00 pm »
Hey, I just discovered "Fixing crashes on exit" (or something like that) on the Roadmap... I do not encounter crashes anymore since I am deleting all Images and Fonts, stored in a manager class, before exiting...
Maybe this will help someone here...

13
Window / KeyCodes missing...
« on: August 05, 2008, 12:05:56 am »
Could you possibly offer a way to get the real raw scancodes/virtual key codes with flags like shift, alt, ctrl and so on, without further processing them to sf::Key::Codes? I am asking because shift+1 and all other numbers (expect 7 and 0) give me 0 as key code, and so do the german Umlauts and a lot of other keys with shift or ctrl pressed...

14
Window / Memory Leaks in sf::RenderWindow
« on: August 04, 2008, 11:19:18 pm »
Hi again,
because of (minor) memory leaks in my program I started to test sf::RenderWindow (I wanted to see if it leaks memory).
I am using Linux (Ubuntu 64-bit)...

Code: [Select]

int main()
{
while(1)
{
VideoMode v(100,100);
RenderWindow* rw = new RenderWindow(v,"blllaaaaa",Style::Close|Style::Resize,4);
delete rw;
}
}


The memory this code commits is increasing slowly, but steadily.
Is there any way to avoid that? I'm working on a GUI project where in some cases, new RenderWindows are created (like e.g. for a Message Box).
Without spawning windows very fast (it takes a rather long time, you can count the windows manually^^), the program takes 11.0 MB RAM (starting with 5.5 MB RAM) after 7 Minutes.
By the way, the memory leaked per Window seems to increase depending on the size of the window.
I can only estimate the amout of memory leaked per Window, but I think it is between 1 K and 2 K... 270 Windows are something like 250 KB.

It might be a problem with the OS (global GL context or something similar), but the OS does not seem to deallocate the memory, even after half an hour (when the memory the program uses is about 40 MB)...

15
Window / Transperancy of RenderWindow
« on: June 04, 2008, 08:35:07 pm »
Is there any way to make the background color of an RenderWindow invisible?

Pages: [1] 2