Re: Review of gnio, round 1
- From: Alexander Larsson <alexl redhat com>
- To: Dan Winship <danw gnome org>
- Cc: desrt desrt ca, gtk-devel-list <gtk-devel-list gnome org>, gicmo gnome org
- Subject: Re: Review of gnio, round 1
- Date: Tue, 28 Apr 2009 09:58:24 +0200
On Mon, 2009-04-27 at 17:16 -0400, Dan Winship wrote:
> Alexander Larsson wrote:
> > On Mon, 2009-04-27 at 13:22 -0400, Dan Winship wrote:
> >>> g_socket_finalize closes socket even if g_socket_close() is already
> >>> closed, need to add an is_closed variable. We should also check this in
> >>> all operations so that we don't accidentally call stuff on an fd that
> >>> may have been reused by now.
> >> libsoup's solution here is to implement "close" as
> >> shutdown(fd,SHUT_RDWR), and only actually call close(fd) at finalization
> >> time.
> > Whats the advantage here over close() and then setting some is_closed
> > bit?
> Well, you don't need an is_closed bit, and you don't need to add a
> special check to every op. You just try to recv() or send() or whatever,
> and get back ENOTCONN (or whatever it is), and handle that normally just
> like if it had been the remote end that closed the connection.
Well, in GSocket we have to check the construction_error every time
anyway, so this is not a huge issue.
> In libsoup it's also important because it's thread-safe/non-racy. That
> may not be a relevant criterion for GSocket, although the source
> returned by g_socket_create_source() could create similar problems; you
> need to be certain that any such sources are destroyed before you call
> g_socket_close(), or else they could trigger falsely if the fd gets
> reused. Delaying close() until finalization makes that easy because then
> you can just have the source hold a ref on the socket to ensure that the
> fd doesn't get closed.
Yeah, this is an interesting aspect. I need to think about it.
] [Thread Prev