Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Technical Support » Other » i have run into a problem...
i have run into a problem... [message #213132] Mon, 14 August 2006 02:47 Go to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
i have run into a problem that i cannot solve:

index.php?t=getfile&id=1517&private=0

if i ignore the error i can telnet port 3002 and send data over fine the fds will print it. so why do i get it?

#include "Socket.h"
#include <string>
#include <windows.h>
using namespace std;

DWORD WINAPI parse(LPVOID lpParam)
{

	SocketServer in(3002,5);
	while (1) 
	{
		Socket* s=in.Accept();
		while (1) 
		{
			std::string r = s->ReceiveLine();
			if (r.empty()) 
				break;
			Console_Output(r.c_str());
		}
	}
	return 0;
}


if i comment this function body out(exept "return 0;") it will not error.

here is the SocketServer code: http://www.adp-gmbh.ch/win/misc/sockets.html
  • Attachment: problem.JPG
    (Size: 128.98KB, Downloaded 196 times)
Re: i have run into a problem... [message #213133 is a reply to message #213132] Mon, 14 August 2006 03:01 Go to previous messageGo to next message
light is currently offline  light
Messages: 988
Registered: January 2005
Karma: 0
Colonel
I'm more a Java person but i'll ask the stupid questions anyway.

1. Does break; break both while loops of just one? (And why do you have 2 whie loops anyway? Why not this:

Quote:


#include "Socket.h"
#include <string>
#include <windows.h>
using namespace std;

DWORD WINAPI parse(LPVOID lpParam)
{

SocketServer in(3002,5);
Socket* s=in.Accept();
std::string r = "";
while (true)
{
r = s->ReceiveLine();
if (r.empty()) {
break;
}
else {
Console_Output(r.c_str());
}
}
}


2. Would it not save resources and allocation to declare your strong outside your second while loop?

3. EDIT: Wait, on reflection using return 0; inside a method that is not main() is probably your issue. Try removing it. Return 0 basically means "All went well, terminate program, but only main() should call it.


http://www.azupload.com/displayImage.php/setid2745.png
Re: i have run into a problem... [message #213138 is a reply to message #213133] Mon, 14 August 2006 04:07 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
light wrote on Mon, 14 August 2006 11:01

I'm more a Java person but i'll ask the stupid questions anyway.

1. Does break; break both while loops of just one? (And why do

it will just break the loop that it is in.

light wrote on Mon, 14 August 2006 11:01


2. Would it not save resources and allocation to declare your strong outside your second while loop?


Yes. do you mean "string" *not sarcasticly*

light wrote on Mon, 14 August 2006 11:01


3. EDIT: Wait, on reflection using return 0; inside a method that is not main() is probably your issue. Try removing it. Return 0 basically means "All went well, terminate program, but only main() should call it.



No, the decloration suggests that it should return a DWORD. return 0; does not mean "all went well", it means in "main" terminate program with exit code 0.

in any function, as far as i know, exept a thread return 0 means that the function when finished will be equal to 0. in breif terms. this may not be all correct, but it is when i think of it.


BTW: a "DWORD" is a number (i think) i don't see why you can't just use "int"

thanks for your reply.

[Updated on: Mon, 14 August 2006 04:08]

Report message to a moderator

Re: i have run into a problem... [message #213249 is a reply to message #213132] Mon, 14 August 2006 16:43 Go to previous messageGo to next message
light is currently offline  light
Messages: 988
Registered: January 2005
Karma: 0
Colonel
In that case won't your code enter an infinite loop?

http://www.azupload.com/displayImage.php/setid2745.png
Re: i have run into a problem... [message #213252 is a reply to message #213132] Mon, 14 August 2006 16:46 Go to previous messageGo to next message
danpaul88 is currently offline  danpaul88
Messages: 5795
Registered: June 2004
Location: England
Karma: 0
General (5 Stars)
Also, your code says while(l), but as far as I can see you have not initialised l... you probably need to do
int l = 1;
or something before starting the while loops (unless its defined in one of those include files)




EDIT: And yes, that code would produce an infinite loop.


http://steamsignature.com/card/1/76561197975867233.png

[Updated on: Mon, 14 August 2006 16:46]

Report message to a moderator

Re: i have run into a problem... [message #213344 is a reply to message #213132] Tue, 15 August 2006 06:49 Go to previous message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
the code doesn't say "while(l)" it says "while(1);" since it is a new thread it doesn't matter if it goes into a infinit loop because it wont halt the program. it goes into an infinite loop to recive data on port 3002.


after alot of debuggung, i have fixed it. it turns out that LoadScopes() function must be called 2 times because i put my function call just after that. when it got called the 2nd time it tryed to open port 3002 which is already open and it crashes.
Previous Topic: just a quick question...
Next Topic: vid card
Goto Forum:
  


Current Time: Sun Apr 28 08:36:03 MST 2024

Total time taken to generate the page: 0.00638 seconds