English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 15 April 2017, 17:41   #1
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
NetLib for StormC

Hi all!

So, Tumo and I made great progress in compiling AmiModRadio with StormC, hopefully to use its debugger and debug crashes on Honx's and Tumo's configs...

Now, one last step: linking AmiModRadio with AmiTCP net.lib... The problem here is that AmiTCP provides a version of net.lib for SAS/C and it seems difficult for me to compile its source with StormC...

Has anyone a version of net.lib for StormC? I guess that I am not the first one to want sockets in StormC

Thanks in advance!
tygre is offline  
Old 15 April 2017, 18:40   #2
patrik
Registered User
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 40
Posts: 598
Unless you have a need for the extra functions available in net.lib, you should be fine by just opening bsdsocket.library and including <proto/socket.h> and at least <sys/socket.h>.
patrik is offline  
Old 15 April 2017, 19:47   #3
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Hi Patrik!

Thanks for your help! This is what I did, I included:

clib/socket_protos.h
sys/socket.h

and my code compiles fine but at linking time, functions like

connect
recv
...

are missing...

Am I doing something wrong?

Thanks!

Last edited by tygre; 15 April 2017 at 19:50. Reason: Completed post
tygre is offline  
Old 15 April 2017, 19:57   #4
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
PS. Replacing clib/socket_proto.h by proto/socket.h makes no difference: still some functions are missing at linking time
tygre is offline  
Old 15 April 2017, 23:01   #5
patrik
Registered User
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 40
Posts: 598
Sorry, I should not have "helped" as I have no experience with StormC. However, I have used bsdsocket.library both with SAS/C and VBCC for more than ten years without linking with net.lib, using the method above, which should work as it is a library like any other.
patrik is offline  
Old 16 April 2017, 02:17   #6
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Yes, indeed, my code compiles fine with VBCC... I have as libraries:
  • amiga
  • miami
  • posix
so, I am thinking that I would need the equivalent of miami (net.lib?) in StormC too... Against which libs do you link your code?

Thanks!
tygre is offline  
Old 16 April 2017, 17:26   #7
patrik
Registered User
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 40
Posts: 598
Take everything below with a grain of salt as I might have missed several aspects/details.

Normally with vbcc I don't link with any specific link libraries unless I need some function or data from them. The only thing vbcc links with automatically then is vc.lib.

Say if I wanted to use NewList() from amiga.lib, then I would link it, but otherwise not.

This is when using <proto/xyz.h> though, which I have understood defines the library functions in such way that the compiler will put the arguments for the library function in the correct registers as specified in the autodoc and call the function directly, which is the most efficient way to do it. How to do it is compiler specific (vbcc for example has a proto directory supplied with such files for all amigaos libraries for example).

If you use clib/proto_xyz.h>, the library functions will be defined as normal C functions where the arguments normally are passed on the stack, which requires some stub/wrapper code to do the actual library function call with registers correctly populated. These stubs/wrappers are as far as I know supplied in link libraries. I think amiga.lib for example contains all such stubs /wrappers for the amigaos library functions. I would assume net.lib also got the stubs/wrappers for bsdsocket.library apart from the actual functions it itself contains.

Btw, I have been using the Roadshow SDK for bsdsocket.library code for quite a while and it doesn't even include a net.lib, so I guess it assumes you would want to use <proto/socket.h>.
patrik is offline  
Old 18 April 2017, 05:43   #8
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Hi Patrik!

Quote:
Originally Posted by patrik View Post
Take everything below with a grain of salt as I might have missed several aspects/details.
Thanks!

Quote:
Originally Posted by patrik View Post
Normally with vbcc I don't link with any specific link libraries unless I need some function or data from them. The only thing vbcc links with automatically then is vc.lib.

Say if I wanted to use NewList() from amiga.lib, then I would link it, but otherwise not.

This is when using <proto/xyz.h> though, which I have understood defines the library functions in such way that the compiler will put the arguments for the library function in the correct registers as specified in the autodoc and call the function directly, which is the most efficient way to do it. How to do it is compiler specific (vbcc for example has a proto directory supplied with such files for all amigaos libraries for example).
Thank you for your explanations! It makes sense and I finally understand the difference between "normal" includes and "proto"s!

Quote:
Originally Posted by patrik View Post
If you use clib/proto_xyz.h>, the library functions will be defined as normal C functions where the arguments normally are passed on the stack, which requires some stub/wrapper code to do the actual library function call with registers correctly populated. These stubs/wrappers are as far as I know supplied in link libraries. I think amiga.lib for example contains all such stubs /wrappers for the amigaos library functions. I would assume net.lib also got the stubs/wrappers for bsdsocket.library apart from the actual functions it itself contains.
However, even when replacing clib/... with proto/..., StormC still asks for the functions... Here is what I have in one of my file:

#include <stdio.h>
#include <stdlib.h>
#include <dos/dos.h> // For RETURN_OK, RETURN_ERROR
#include <sys/types.h> // For u_short
#include <proto/exec.h> // For OpenLibrary() and CloseLibrary()
#include <netdb.h> // Sockets and such
#include <proto/socket.h> // Sockets and such
#include <sys/socket.h> // Sockets and such

What am I missing? Again, with VBCC, it compiles fine... only with StormC... I must be overlooking something...

Quote:
Originally Posted by patrik View Post
Btw, I have been using the Roadshow SDK for bsdsocket.library code for quite a while and it doesn't even include a net.lib, so I guess it assumes you would want to use <proto/socket.h>.
Yes, that would make sense totally but then StormC still complains

Cheers!
tygre is offline  
Old 18 April 2017, 06:10   #9
Minuous
Coder/webmaster/gamer
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,208
You don't need net.lib for send(), recv(), etc.

You might want to look at the source code for the Report+ application (http://amigan.1emu.net/releases/ReportPlus.lha); it is written for StormC and has full source included.
Minuous is online now  
Old 18 April 2017, 12:41   #10
patrik
Registered User
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 40
Posts: 598
Quote:
Originally Posted by tygre View Post
What am I missing? Again, with VBCC, it compiles fine... only with StormC... I must be overlooking something...
Maybe StormC has no specific proto/socket.h and defaults to the clib/proto_socket.h file. I see that vbcc has an included proto/socket.h, which will override the proto of the badsocket.library SDK. This is correct as I cannot imagine that the old AmiTCP/Miami SDK:s had VBCC style proto support. The Roadshow SDK on the other hand is more recent and has vbcc support in its proto.

Which bsdsocket.library SDK are you using?
patrik is offline  
Old 18 April 2017, 23:32   #11
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Quote:
Originally Posted by Minuous View Post
You don't need net.lib for send(), recv(), etc.

You might want to look at the source code for the Report+ application (http://amigan.1emu.net/releases/ReportPlus.lha); it is written for StormC and has full source included.
Thank you Minuous but I don't seem to find code related to sockets in Report+, am I looking not straight?

Cheers!
tygre is offline  
Old 18 April 2017, 23:34   #12
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Quote:
Originally Posted by patrik View Post
Maybe StormC has no specific proto/socket.h and defaults to the clib/proto_socket.h file. I see that vbcc has an included proto/socket.h, which will override the proto of the badsocket.library SDK. This is correct as I cannot imagine that the old AmiTCP/Miami SDK:s had VBCC style proto support. The Roadshow SDK on the other hand is more recent and has vbcc support in its proto.

Which bsdsocket.library SDK are you using?
Yes, that would make sense... maybe I should use Roadshow SDK... Right now, I am using AmiTCP-SDK-4.3, could that be the cause of my troubles?

Cheers!
tygre is offline  
Old 19 April 2017, 01:40   #13
Minuous
Coder/webmaster/gamer
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,208
Quote:
Originally Posted by tygre View Post
Thank you Minuous but I don't seem to find code related to sockets in Report+, am I looking not straight?
There is code for composing and sending emails in f1.c, and for downloading files from a web server in rp.c.
Minuous is online now  
Old 19 April 2017, 12:45   #14
patrik
Registered User
patrik's Avatar
 
Join Date: Jan 2005
Location: Umeå
Age: 40
Posts: 598
Quote:
Originally Posted by tygre View Post
Yes, that would make sense... maybe I should use Roadshow SDK... Right now, I am using AmiTCP-SDK-4.3, could that be the cause of my troubles?

Cheers!
If the problem is that your current SDK doesn't have support for StormC3 in its protos and StormC itself doesn't include overriding protos for bsdsocket.library, then changing SDK will only help if the new SDK has support for StormC3 in its protos.

It is also possible to generate missing protos for more or less any compiler from .fd files which should be included in the SDK. I don't know what tool to use for StormC, but with vbcc you use the included fd2pragma for example. Should be a chapter about this in the StormC3 manual.
patrik is offline  
Old 20 April 2017, 16:25   #15
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Hi Minuous and Patrik!

Quote:
Originally Posted by patrik View Post
If the problem is that your current SDK doesn't have support for StormC3 in its protos and StormC itself doesn't include overriding protos for bsdsocket.library, then changing SDK will only help if the new SDK has support for StormC3 in its protos.

It is also possible to generate missing protos for more or less any compiler from .fd files which should be included in the SDK. I don't know what tool to use for StormC, but with vbcc you use the included fd2pragma for example. Should be a chapter about this in the StormC3 manual.
Thank you for the code and advices! I will try to compile the code and see what happens: if it can compile, I will know that something is wrong with my code... if it doesn't, then I will know that something is wrong with my install of StormC

I'll keep you posted!

Cheers!
tygre is offline  
Old 21 April 2017, 06:09   #16
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Quote:
Originally Posted by Minuous View Post
There is code for composing and sending emails in f1.c, and for downloading files from a web server in rp.c.
Hi Minuous!

Was ReportPlus written with StormC 4? I tried to load its project file (.¶) in StormC 3 and it complains that the file is "not a project file"?

Cheers!
tygre is offline  
Old 21 April 2017, 07:33   #17
Minuous
Coder/webmaster/gamer
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,208
Yes, it was written with StormC 4, but it uses the StormC 3 compiler.
Minuous is online now  
Old 18 May 2017, 01:55   #18
tygre
Returning fan!

tygre's Avatar
 
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 851
Hi Minuous!

I looked at the code and I think that I understand why ReportPlus compiles with StormC 3: it "defines" the libcalls in the C files. For example, at the beginning of f1.c, there is:

Code:
struct hostent* gethostbyname(const UBYTE* name);
	LONG recv(LONG s, UBYTE* buf, LONG len, LONG flags); /* V3 */
	LONG closesocket(LONG d);
	LONG connect(LONG s, const struct sockaddr* name, LONG namelen);
	LONG send(LONG s, const UBYTE* msg, LONG len, LONG flags);
	LONG socket(LONG domain, LONG type, LONG protocol);
	LONG shutdown(LONG s, LONG how);

	#pragma libcall SocketBase gethostbyname D2 801
	#pragma libcall SocketBase recv 4E 218004
	#pragma libcall SocketBase closesocket 78 001
	#pragma libcall SocketBase connect 36 18003
	#pragma libcall SocketBase send 42 218004
	#pragma libcall SocketBase socket 1E 21003
	#pragma libcall SocketBase shutdown 54 1002
which allows compiling the code Now, I can sure do the same thing in my code (caveat: find the proper arguments for other functions that I use, like inet_addr()) but is it "clean" to do that?

Cheers!

Last edited by tygre; 18 May 2017 at 02:17.
tygre is offline  
Old 18 May 2017, 06:30   #19
Minuous
Coder/webmaster/gamer
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,208
I don't recall the exact reason why I did it that way. It's generally considered better to use include files. Presumably there was some issue with the include file/compiler/linker etc. that made this the easiest way. Either way, of course, the resulting executable will be the same.
Minuous is online now  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
dirent.h in StormC v3.0 tygre Coders. C/C++ 6 19 April 2017 01:34
StormC PPC fryguy request.Apps 1 17 August 2014 22:20
Need help: StormC 3 AlfaRomeo Coders. General 27 10 October 2008 12:31
StormC V4 Oneillsite request.Apps 4 06 October 2006 23:49
StormC V4 FromWithin Coders. General 13 24 July 2005 17:20

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 15:31.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.10571 seconds with 15 queries