[ale] Ms -> Linux porting pointer sought

Christopher Fowler cfowler at outpostsentinel.com
Thu May 15 15:38:26 EDT 2003


On Thu, May 15, 2003 at 11:06:44AM -0400, John Mills wrote:
> That's what I'm doing. Numeric types have not been a problem to define,
> but I'm looking for *nix synonyms for generic 'HANDLE' (U16, I guess?)  
> and 'SOCKET'. I don't have much in the way of MsWin examples to look at, 
> compared to all the *nix sources. I admit to being 'Windows challenged'.
> 

I think HANDLES are just pointers cast to int.  That is what I do
when I use handles in C.  I would simply just recreate the data
as a structure that is dynamiclly allocated.  

static HANDLE
ptr2handle(void *ptr) {
  return (int)ptr;
}

One reason to do this could be to hid the API details from
the application programmer to make it easier on them.  I guess
kinda like private data types in Java that requres methods
to retrieve.  Plus, with the handle method, you can store much
information and keep it simple in the application.  Much of the work
can be done in the library.

/* socket.c */

typedef int SOCKET;

struct {
    struct sockaddr_in local;
    struct sockaddr_in peer;
    int fd;
} socket_data;


static SOCKET
ptr2handle(struct socket_data *ptr) {
  return(int)ptr;
}

/* END */


These are only examples.  You can do whatever.

Chris

_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list