Add code for simulating a SDP server present in the host
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34330 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
af10de93a4
commit
e97e2846af
@ -91,6 +91,7 @@ bool BluetoothServer::QuitRequested(void)
|
||||
|
||||
/* stop the SDP server thread */
|
||||
fIsShuttingDown = true;
|
||||
|
||||
status_t threadReturnStatus;
|
||||
wait_for_thread(fSDPThreadID, &threadReturnStatus);
|
||||
printf("SDP server thread exited with: %s\n", strerror(threadReturnStatus));
|
||||
@ -130,10 +131,13 @@ void BluetoothServer::ReadyToRun(void)
|
||||
fSDPThreadID = spawn_thread(SDPServerThread, "SDP server thread",
|
||||
B_NORMAL_PRIORITY, this);
|
||||
|
||||
//#define _USE_SDP_SERVER
|
||||
#ifdef _USE_SDP_SERVER
|
||||
if (fSDPThreadID <= 0 || resume_thread(fSDPThreadID) != B_OK) {
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP,
|
||||
"Failed launching the SDP server thread: %x\n", fSDPThreadID);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -453,8 +457,7 @@ BluetoothServer::SDPServerThread(void* data)
|
||||
int socketServer;
|
||||
int client;
|
||||
status_t status;
|
||||
char buff[512] = "";
|
||||
|
||||
char buffer[512] = "";
|
||||
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP, "SDP server thread up...\n");
|
||||
|
||||
@ -469,7 +472,7 @@ BluetoothServer::SDPServerThread(void* data)
|
||||
// bluetooth adapter
|
||||
loc_addr.l2cap_family = AF_BLUETOOTH;
|
||||
loc_addr.l2cap_bdaddr = *BDADDR_ANY;
|
||||
loc_addr.l2cap_psm = B_HOST_TO_LENDIAN_INT16(1); // correct?
|
||||
loc_addr.l2cap_psm = B_HOST_TO_LENDIAN_INT16(1);
|
||||
loc_addr.l2cap_len = sizeof(struct sockaddr_l2cap);
|
||||
|
||||
status = bind(socketServer, (struct sockaddr *)&loc_addr, sizeof(struct sockaddr_l2cap));
|
||||
@ -490,7 +493,6 @@ BluetoothServer::SDPServerThread(void* data)
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
while (!server->fIsShuttingDown) {
|
||||
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Waiting connection for socket %d ...\n", socketServer);
|
||||
@ -500,18 +502,20 @@ BluetoothServer::SDPServerThread(void* data)
|
||||
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Incomming connection... %ld\n", client);
|
||||
|
||||
ssize_t leng = recv(client, buff, 29 , 0);
|
||||
if (leng == -1) {
|
||||
ssize_t receivedSize;
|
||||
|
||||
do {
|
||||
receivedSize = recv(client, buffer, 29 , 0);
|
||||
if (receivedSize < 0)
|
||||
Output::Instance()->Post("Error reading client socket\n", BLACKBOARD_SDP);
|
||||
|
||||
}
|
||||
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Received from SDP client: %ld:\n", leng);
|
||||
for (int i = 0; i < leng ; i++)
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP, "%x:", buff[i]);
|
||||
else {
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP, "Received from SDP client: %ld:\n", receivedSize);
|
||||
for (int i = 0; i < receivedSize ; i++)
|
||||
Output::Instance()->Postf(BLACKBOARD_SDP, "%x:", buffer[i]);
|
||||
|
||||
Output::Instance()->Post("\n", BLACKBOARD_SDP);
|
||||
|
||||
}
|
||||
} while (receivedSize >= 0);
|
||||
|
||||
/* fd_set fdSet;
|
||||
FD_ZERO(&fdSet);
|
||||
@ -520,13 +524,12 @@ BluetoothServer::SDPServerThread(void* data)
|
||||
struct timeval timeout;
|
||||
memset(&timeout, 0, sizeof(timeout));
|
||||
// TODO initialize timeout!
|
||||
|
||||
int ret = select(1, &fdSet, NULL, NULL, &timeout);
|
||||
printf("ready to read descriptors: %d\n", ret);
|
||||
*/
|
||||
|
||||
snooze(5000000);
|
||||
Output::Instance()->Post("Waiting for next connection...\n", BLACKBOARD_SDP);
|
||||
Output::Instance()->Post("\nWaiting for next connection...\n", BLACKBOARD_SDP);
|
||||
}
|
||||
|
||||
/* Close the socket */
|
||||
|
Loading…
Reference in New Issue
Block a user