Click here to Skip to main content
14,737,364 members
Home » Discussions » Linux Programming
   

Linux Programming

 
AnswerRe: Can "cast looses precision " error be optioned out ? Pin
Richard MacCutchan3-Mar-20 5:43
mveRichard MacCutchan3-Mar-20 5:43 
AnswerRe: Can "cast looses precision " error be optioned out ? Pin
Daniel Pfeffer3-Mar-20 5:52
professionalDaniel Pfeffer3-Mar-20 5:52 
GeneralMessage Closed Pin
9-Mar-20 15:21
Memberwatchmeoni9-Mar-20 15:21 
AnswerRe: Can "cast looses precision " error be optioned out ? Pin
k50543-Mar-20 6:52
mvek50543-Mar-20 6:52 
AnswerSOLVED Re: Can "cast looses precision " error be optioned out ? Pin
Vaclav_3-Mar-20 9:00
MemberVaclav_3-Mar-20 9:00 
GeneralRe: SOLVED Re: Can "cast looses precision " error be optioned out ? Pin
k50543-Mar-20 11:36
mvek50543-Mar-20 11:36 
GeneralRe: SOLVED Re: Can "cast looses precision " error be optioned out ? Pin
Vaclav_3-Mar-20 14:47
MemberVaclav_3-Mar-20 14:47 
QuestionBluetooth socket failures Pin
Vaclav_28-Feb-20 6:43
MemberVaclav_28-Feb-20 6:43 
I am looking for somebody who can help me to resolve this bluetooth issue.
( I'll ignore any replies NOT discussing / leading to resolution , including insults and RTFM comments )


Included is "bare bones " bluetooth code , I have not included any necessary #includes / library , but if it will help I can add them later if necessary.

I am still having an issue with "address already in use" , BUT my question for now is

why I cannot close and successfully reallocate "socket" ?

I understand that some functions DO NOT generate valid "errno" hence "invalid argument" is really somewhat bogus perror message, however SECOND call to socket should generate "Success" .

Again please concentrate on that for now.

Code output

RPI_BT_SERVER _X86 
date version Feb 28 2020
test time 10:17:50
 BRAEK @line 333
STATUS allocate socket : Success
STATUS close socket : Invalid argument
STATUS reallocate socket : Invalid argument this is the issue 
STATUS bind : Address already in use
STATUS listen : File descriptor in bad state
STATUS accept : File descriptor in bad state
accepted connection from 00:00:00:00:00:00


Code snippet:


<pre>	struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
	char buf[1024] = { 0 };
	int socket_fd, client_fd, bytes_read;
	socklen_t opt = sizeof(rem_addr);

	// allocate socket
	socket_fd= socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
	perror("STATUS allocate socket ");

	// close socket
	close(socket_fd);
	perror("STATUS close socket ");
	// re allocate socket
	socket_fd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
	perror("STATUS reallocate socket ");

	// bind socket to port 1 of the first available
	// local bluetooth adapter
	loc_addr.rc_family = AF_BLUETOOTH;

	struct hci_dev_info device_info;
	hci_devinfo(0, &device_info);

//  exit(1);

	loc_addr.rc_bdaddr = device_info.bdaddr; //   {"00:15:83:15:A2:CB"}; // "*BDADDR_ANY;
	loc_addr.rc_channel = (uint8_t) 1;
	bind(socket_fd, (struct sockaddr*) &loc_addr, sizeof(loc_addr));
	perror("STATUS bind ");
	// put socket into listening mode
	listen(socket_fd, 1);
	perror("STATUS listen ");
	// accept one connection
	client_fd = accept(socket_fd, (struct sockaddr*) &rem_addr, &opt);
	perror("STATUS accept ");
	ba2str(&rem_addr.rc_bdaddr, buf);
	fprintf(stderr, "accepted connection from %s\n", buf);
	memset(buf, 0, sizeof(buf));

	// read data from the client
	bytes_read = read(client_fd, buf, sizeof(buf));
	if (bytes_read > 0) {
		printf("received [%s]\n", buf);
	}

	// close connection
	close(client_fd);
	close(socket_fd);


AnswerRe: Bluetooth socket failures Pin
Richard MacCutchan28-Feb-20 7:32
mveRichard MacCutchan28-Feb-20 7:32 
GeneralRe: Bluetooth socket failures Pin
Vaclav_28-Feb-20 8:12
MemberVaclav_28-Feb-20 8:12 
GeneralRe: Bluetooth socket failures Pin
k505429-Feb-20 7:14
mvek505429-Feb-20 7:14 
GeneralRe: Bluetooth socket failures Pin
Vaclav_29-Feb-20 9:27
MemberVaclav_29-Feb-20 9:27 
GeneralRe: Bluetooth socket failures Pin
Richard MacCutchan29-Feb-20 22:19
mveRichard MacCutchan29-Feb-20 22:19 
GeneralRe: Bluetooth socket failures Pin
Vaclav_1-Mar-20 5:02
MemberVaclav_1-Mar-20 5:02 
GeneralRe: Bluetooth socket failures Pin
Vaclav_28-Feb-20 9:32
MemberVaclav_28-Feb-20 9:32 
QuestionRunning console apps on windows 7 Pin
CalinNegru(fearless_)23-Feb-20 21:07
MemberCalinNegru(fearless_)23-Feb-20 21:07 
AnswerRe: Running console apps on windows 7 Pin
Victor Nijegorodov23-Feb-20 21:45
MemberVictor Nijegorodov23-Feb-20 21:45 
GeneralRe: Running console apps on windows 7 Pin
CalinNegru(fearless_)23-Feb-20 22:22
MemberCalinNegru(fearless_)23-Feb-20 22:22 
AnswerRe: Running console apps on windows 7 Pin
Richard MacCutchan23-Feb-20 21:59
mveRichard MacCutchan23-Feb-20 21:59 
GeneralRe: Running console apps on windows 7 Pin
CalinNegru(fearless_)23-Feb-20 22:21
MemberCalinNegru(fearless_)23-Feb-20 22:21 
GeneralRe: Running console apps on windows 7 Pin
jsc4229-Feb-20 12:16
professionaljsc4229-Feb-20 12:16 
Questiongetting started with ASM, what compilers do you use? Pin
CalinNegru(fearless_)21-Feb-20 2:47
MemberCalinNegru(fearless_)21-Feb-20 2:47 
AnswerRe: getting started with ASM, what compilers do you use? Pin
Richard MacCutchan21-Feb-20 2:52
mveRichard MacCutchan21-Feb-20 2:52 
GeneralRe: getting started with ASM, what compilers do you use? Pin
CalinNegru(fearless_)21-Feb-20 3:40
MemberCalinNegru(fearless_)21-Feb-20 3:40 
GeneralRe: getting started with ASM, what compilers do you use? Pin
Richard MacCutchan21-Feb-20 4:54
mveRichard MacCutchan21-Feb-20 4:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.