proposal: libsmbclient functionality addition

Richard Sharpe rsharpe at
Mon Jun 17 16:52:03 GMT 2002

On Mon, 17 Jun 2002, Tom Jansen wrote:

> Hi,
> At the moment, libsmbclient caches connections, which is great. There is one
> problem with that however: if a server closes the connection (idle timeout for
> example) there is no way to get a connection to that server/share combination
> again. Ok, there is one way: restart your application that uses libsmbclient.
> IMHO, this is not an option.

Yes, that is a problem ...
> To solve this problem I want to propose a little change to libsmbclient.c.
> There are two ways to do this: automatically or manually. I'm proposing both.
> add a few functions:
> int smbc_remove_cached_server(char *srv, char *share, char* user, char* pass)
> int smbc_auto_reconnect(int tries)
> The first function would just remove a server from the cache if it's unused.
> This function can be used by the automagic part as weel as the manual mechanism.
> The second function would enable/disable automatic reconnects upon failures (and
> set the number of times tried). These retries would only take place in functions
> calling smbc_server() directly.
> The most important part is detecting these disconnects and acting nice upon
> occurance. I think there are two ways:
> o A callback mechanism to give disconnect messages to the user (libsmbclient.c
> and user-written code).
> o A simple check in smbc_server(): send keepalive packet and check cli->fd for
> errors (in all the clientcode I've seen, the fd is set to -1 on error).

Sending a keep-alive requires that you call down into libsmbclient every 
now and then from the application ... You should be able to detect that 
the connection has gone, as you indicate, on the next time you call down 
to libsmbclient. So, you might not need the keep-alive.

However, from the point of view of GTK+ apps, it would be worth while 
having that.

> I prefer the last for increased simplicity. Maybe the samba gurus disagree but
> that's why I'm posting this here.
> Is there any interest in such code? I'm quite happy to code it up and contribute
> it because I use libsmbclient a lot (as well as samba-server btw (200+ samba
> servers on our network here:-).

Please go ahead. I am really pleased that someone is using it alot.

The next big set of changes I need to make are allowing one program to 
instantiate multiple clients. This is something that is needed ...

Richard Sharpe, rsharpe at, rsharpe at, 
sharpe at

More information about the samba-technical mailing list