Am Dienstag 25 März 2008 schrieb Nick Bransby-Williams:
> > Not when you stick to the API. OTOH, when BtOBEX_TransportConnect()
> > returns with -1, you can ask "errno", don't you?
> >  I must admit, though, that the API lacks there.
>
> Can I ask for a more specific error no? I dont see an API function to do
> that.

see connect(3) manpage

> As a -1 return  from BtOBEX_TransportConnect() does not tell me if the
> connection was:
>
> Refused by server,

if (errno == ECONNREFUSED)

> Timed out,

if (errno == ETIMEDOUT)

> General connection error

Anything else. However, I just see that this will not work as another system 
call is done before the function returns to the user :-(
I created and attached an untested patch that creates a new API function
  int OBEX_GetLastError(obex_t*)
that returns the last errno value (see above) and sets that value for 
BtOBEX_TransportConnect case.

HS
--- openobex.orig/include/obex.h
+++ openobex/include/obex.h
@@ -69,6 +69,8 @@
 int OBEX_SetTransportMTU(obex_t *self, uint16_t mtu_rx, uint16_t mtu_tx_max);
 int OBEX_GetFD(obex_t *self);
 
+int OBEX_GetLastError(obex_t *self);
+
 int OBEX_RegisterCTransport(obex_t *self, obex_ctrans_t *ctrans);
 void OBEX_SetCustomData(obex_t *self, void * data);
 void * OBEX_GetCustomData(obex_t *self);
--- openobex.orig/lib/btobex.c
+++ openobex/lib/btobex.c
@@ -218,6 +218,7 @@
 	return 1;
 
 out_freesock:
+	self->err = errno;
 	obex_delete_socket(self, self->fd);
 	self->fd = -1;
 #endif /* _WIN32 */
--- openobex.orig/lib/obex.c
+++ openobex/lib/obex.c
@@ -127,6 +127,7 @@
 	self->serverfd = -1;
 	self->writefd = -1;
         self->state = MODE_SRV | STATE_IDLE;
+	self->err = 0;
 	
 	/* Init transport */
 	self->trans.type = transport;
@@ -517,6 +518,17 @@
 }
 
 /**
+ * OBEX_GetLastError - get the last system error code
+ * @self: OBEX handle
+ *
+ * Returns a system specific error code.
+ */
+int OBEX_GetLastError(obex_t *self)
+{
+	return self->err;
+}
+
+/**
  * OBEX_Request - Start a request (as client)
  * @self: OBEX handle
  * @object: Object containing request
--- openobex.orig/lib/obex.sym
+++ openobex/lib/obex.sym
@@ -5,6 +5,7 @@
 OBEX_SetUserCallBack
 OBEX_SetTransportMTU
 OBEX_GetFD
+OBEX_GetLastError
 OBEX_RegisterCTransport
 OBEX_SetCustomData
 OBEX_GetCustomData
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Openobex-users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/openobex-users

Reply via email to