Skip to main content
Home Forums 68kMLA Help with TCPExample in Pascal — #7
Post #7 by bbraun
Source Forum68kMLA
CategoryDevelopment
Post DateSun, 20 Oct 2013 - 05:41
Original URLhttps://68kmla.org/bb/threads/help-with-tcpexample-in-pascal.29110/
Post
Code:
function NewPassiveConnection (var cp: connectionIndex; buffersize: longInt; localport: integer; remotehost: longInt; remoteport: integer; dataptr: univ ptr): OSErr;
That's the declaration of the function, it has 6 arguments and returns an OSErr. OSErr is a 16bit number, and is the typical Mac OS error code you see everywhere, including in system dialog boxes when something goes wrong. You can google for the error code, and it should also be defined in a header file with your compiler somewhere. Here is also an old KB article with some of the codes defined.

var cp: connectionIndex - the 'var' means it is a pass by reference, or a pointer, for a type 'connectionIndex'. The 'cp' is just a name, although in the example this would also be the variable 'cp' that is being passed to NewActiveConnection.

buffersize: longInt - the argument is of type longInt, which would be a 32bit value. The name is 'buffersize', and it looks like you can just use the constant Default_TCPBUFFERSIZE that is being passed to NewActiveConnection.

localport: integer - 'integer' being a 16bit value. This is the local port you want to listen on.

remotehost: longInt - longInt being the same size as an IP address, this is the address you want to accept connections from, although you can pass 0 in to accept connections from anywhere.

remoteport: integer - the remote port you want to accept connections from, although you probably want to pass in 0 to accept from any port.

dataptr: univ ptr - This is a pointer to "anything". It appears the wrapper is letting you associate your own data with the connection, and you can get it back when processing events returned by GetConnectionEvent. The sample code calls NewActiveConnection with this parameter as 'nil', or "no value", and you can probably do the same thing for NewPassiveConnection for now.

The way I figured out what the arguments are is I looked in the TCP Libraries folder of the example, at TCPConnections.unit, and what that was doing. Ultimately, it is making a MacTCP call to open a new passive connection, and the arguments for that are described in the MacTCP Programmer's Guide.

mp.ls