• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to delete a socket in the file system
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to delete a socket in the file system


  • Subject: Re: How to delete a socket in the file system
  • From: Chaz McGarvey <email@hidden>
  • Date: Wed, 7 Jul 2004 18:18:58 -0600

On Jul 7, 2004, at 5:58 PM, Andrea -XFox- Govoni wrote:

I need to work with BSD sockets but I have a problem with the bind() system call.
In my code I make a bind() call as follows:

bind(listen_socket, (struct sockaddr *)&mio_ind, sizeof(struct sockaddr);

where listen_socket is an integer returned by socket() and mio_ind is a sockaddr_in struct.

When I want quit I call "close(listen_socket);" but, according with the bind() man page, I have also to unlink the socket created in the file system with bind().

From bind() man page:
"Binding a name in the UNIX domain creates a socket in the file system that must be deleted by the caller when it is no longer needed (using unlink(2))."

The problem is that unlink() requires a file system path as argument, and I don't know the path of the socket created by bind().
How should I call unlink?

I'm on Mac OS X 10.3.4.

You only need to delete the socket if it is a UNIX domain socket (non-network). So if you bind to a port as you would do for a network socket, this doesn't apply. What bind does is binds the socket to the port (or path in the case of a UNIX domain socket). Therefore, the path would be something that you pass to bind and you should already know what it is in order to delete it after you are done with it. This is typically done using the sockaddr_un structure (as opposed to the sockaddr_in typically used for network sockets). And the manual page is correct in that you would use unlink to delete the socket.

But I'm guessing that what you really want to use sockets for is for networking rather than interprocess communication in which case merely closing the socket should clear up the port just fine.

Incidentally, I'd be interested in knowing why it is that the socket "file" is left behind while ports are automatically released if anyone knows.

Chaz McGarvey
http://www.brokenzipper.com
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: How to delete a socket in the file system
      • From: Justin Walker <email@hidden>
References: 
 >How to delete a socket in the file system (From: Andrea -XFox- Govoni <email@hidden>)

  • Prev by Date: How to delete a socket in the file system
  • Next by Date: Re: How to delete a socket in the file system
  • Previous by thread: How to delete a socket in the file system
  • Next by thread: Re: How to delete a socket in the file system
  • Index(es):
    • Date
    • Thread