00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _OASYS_RFCOMM_SERVER_H_
00018 #define _OASYS_RFCOMM_SERVER_H_
00019
00020 #include "config.h"
00021
00022 #ifdef OASYS_BLUETOOTH_ENABLED
00023
00024 #include "BluetoothServer.h"
00025 #include "../thread/Thread.h"
00026
00027 namespace oasys {
00028
00029 class RFCOMMServer : public BluetoothServer {
00030 public:
00031 RFCOMMServer(char* logbase = "/rfcommserver")
00032 : BluetoothServer(SOCK_STREAM,BluetoothSocket::RFCOMM,logbase)
00033 {
00034 }
00035 };
00036
00037 class RFCOMMServerThread : public BluetoothServerThread {
00038 public:
00039 RFCOMMServerThread(char * logbase = "/rfcommserver", int flags = 0)
00040 : BluetoothServerThread(SOCK_STREAM,
00041 BluetoothSocket::RFCOMM,
00042 "oasys::RFCOMMServerThread",
00043 logbase,
00044 flags)
00045 {
00046 }
00047
00048 void set_accept_timeout(int ms) {
00049 accept_timeout_ = ms;
00050 }
00051
00052
00053 int rc_bind() {
00054 int res = -1;
00055 for (channel_ = 1; channel_ <= 30; channel_++) {
00056 if ((res = bind()) != 0) {
00057
00058
00059 if (errno != EADDRINUSE) {
00060 log_err("error binding to %s:%d: %s",
00061 bd2str(local_addr_), channel_, strerror(errno));
00062 if (errno == EBADFD) close();
00063 return res;
00064 }
00065 } else {
00066
00067
00068 return res;
00069 }
00070
00071 }
00072
00073 log_err("Scanned all local RFCOMM channels but unable to bind to %s",
00074 bd2str(local_addr_));
00075 return -1;
00076 }
00077 };
00078
00079 }
00080
00081 #endif
00082 #endif