tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

RE: closing a socket in kernel mode



I solved my problem. I did not realize that getsock would increase the
usecount. I was doing that periodically to convert an "int socket" to a
"struct socket *". I simply added FILE_UNUSE(fp, curlwp) after the call to
getsock and that reduced usecount. Now I can close properly.

Eddy

-----Original Message-----
From: tech-kern-owner%NetBSD.org@localhost 
[mailto:tech-kern-owner%NetBSD.org@localhost] On
Behalf Of David Young
Sent: Wednesday, June 04, 2008 12:12 PM
To: tech-kern%NetBSD.org@localhost
Subject: Re: closing a socket in kernel mode

On Wed, Jun 04, 2008 at 10:31:29AM -0400, Eddy Quicksall wrote:
> I'm using sockets in kernel level. I use the following functions. I'm
having
> trouble closing the socket. What happens is that the file is not freed up
> and I eventually get error 24 (Too many open files). Any ideas?
> 
> sys___socket30()
> soaccept()
> so_send()
> sys_shutdown() (this causes the FIN to be properly sent)

If you can, avoid using the sys_XXX routines.  Instead, directly use
the same soXXX routines that the sys_ routines call.

> -- and finally to close the file I do this, but it ends up sleeping in
> sys_close ---
> -- if I print fp->f_usecount I see it is 0xf. It was suggested that I try
> FILE_UNUSE, 
> -- but using FILE_UNUSE(fp,curlwp) does not change that f_usecount nor
does
> it
> -- keep sys_close from sleeping
> SCARG(&CloseArgs, fd) = s;
> sys_close(curlwp, &CloseArgs, retval);

Is a file descriptor strictly necessary?

In -current sources, you may find some examples of what you need to do
in gre(4).

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 278-3933 ext 24



Home | Main Index | Thread Index | Old Index