Skip navigation.
Home
The QNX Community Portal

View topic - TCP Socket in Photon

TCP Socket in Photon

Isn't the name clear?

TCP Socket in Photon

Postby Drex » Thu Oct 02, 2003 4:07 pm

I am new to Photon so excuse my ignorance. I am trying to setup (and open) a TCP socket file descriptor(fd) that i can then use as a global variable to communicate with (in the callback functions).

I have tried declaring the fd in a startup function then using it in my callbacks as an extern. If i do this, it compiles but the program crashes as soon as the callback is started. I am worried that the variable is being destroyed when the startup function finishes.

However if i declare the file descriptor in the main file then use it as an extern, the compiler says it cant find it when it is referenced in the callbacks.

Can anyone help me. I am not sure if this is the correct approach?
Drex
Active Member
 
Posts: 17
Joined: Tue Jul 29, 2003 4:55 pm

Re: TCP Socket in Photon

Postby rgallen » Thu Oct 02, 2003 7:47 pm

Drex wrote:I am new to Photon so excuse my ignorance. I am trying to setup (and open) a TCP socket file descriptor(fd) that i can then use as a global variable to communicate with (in the callback functions).

I have tried declaring the fd in a startup function then using it in my callbacks as an extern. If i do this, it compiles but the program crashes as soon as the callback is started. I am worried that the variable is being destroyed when the startup function finishes.

However if i declare the file descriptor in the main file then use it as an extern, the compiler says it cant find it when it is referenced in the callbacks.

Can anyone help me. I am not sure if this is the correct approach?



Are you declaring the variable in function scope (i.e. as an auto) ? If so, then your approach is flawed, as the file descriptor is indeed destroyed as the PC moves out of function scope. If you are declaring the file descriptor in file scope then there is nothing fundamentally wrong with your approach, however, in Photon it can sometimes be difficult to tell the order of callbacks, and perhaps the callback that initializes the file descriptor (i.e. does the open()) is called after a callback that tries to use the file descriptor.
rgallen
QNX Master
 
Posts: 671
Joined: Thu Jul 11, 2002 6:48 pm

Postby Drex » Fri Oct 03, 2003 2:44 pm

Thanks rgallen

I had declared the fd in file scope. But the program still crashes - very strange. I dont think it could be the order if the callbacks as the setup function is pre-realise, but the user functions are only triggered by buttons.

I started again, with a new project and now works fine!?!
Drex
Active Member
 
Posts: 17
Joined: Tue Jul 29, 2003 4:55 pm

Postby rangaraju99 » Tue Oct 07, 2003 6:27 am

Check for the success of opening the file descriptor. If not successful the return with Pt_CONTINUE then there won't be any problems. Atleast the program won't crash

fp = fopen(...);
if(!fp)
return( Pt_CONTINUE);

The above statements ensure that ur application doesn't crash
rangaraju99
Active Member
 
Posts: 10
Joined: Tue Sep 23, 2003 8:14 am


Return to GUI Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest