Click here to Skip to main content
16,016,306 members
Home / Discussions / Linux Programming
   

Linux Programming

 
QuestionCan "cast looses precision " error be optioned out ? Pin
Vaclav_3-Mar-20 4:10
Vaclav_3-Mar-20 4:10 
AnswerRe: Can "cast looses precision " error be optioned out ? Pin
Richard MacCutchan3-Mar-20 4:43
mveRichard MacCutchan3-Mar-20 4:43 
AnswerRe: Can "cast looses precision " error be optioned out ? Pin
Daniel Pfeffer3-Mar-20 4:52
professionalDaniel Pfeffer3-Mar-20 4:52 
AnswerRe: Can "cast looses precision " error be optioned out ? Pin
k50543-Mar-20 5:52
mvek50543-Mar-20 5:52 
AnswerSOLVED Re: Can "cast looses precision " error be optioned out ? Pin
Vaclav_3-Mar-20 8:00
Vaclav_3-Mar-20 8:00 
GeneralRe: SOLVED Re: Can "cast looses precision " error be optioned out ? Pin
k50543-Mar-20 10:36
mvek50543-Mar-20 10:36 
GeneralRe: SOLVED Re: Can "cast looses precision " error be optioned out ? Pin
Vaclav_3-Mar-20 13:47
Vaclav_3-Mar-20 13:47 
QuestionBluetooth socket failures Pin
Vaclav_28-Feb-20 5:43
Vaclav_28-Feb-20 5: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:


C++
<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 6:32
mveRichard MacCutchan28-Feb-20 6:32 
GeneralRe: Bluetooth socket failures Pin
Vaclav_28-Feb-20 7:12
Vaclav_28-Feb-20 7:12 
GeneralRe: Bluetooth socket failures Pin
k505429-Feb-20 6:14
mvek505429-Feb-20 6:14 
GeneralRe: Bluetooth socket failures Pin
Vaclav_29-Feb-20 8:27
Vaclav_29-Feb-20 8:27 
GeneralRe: Bluetooth socket failures Pin
Richard MacCutchan29-Feb-20 21:19
mveRichard MacCutchan29-Feb-20 21:19 
GeneralRe: Bluetooth socket failures Pin
Vaclav_1-Mar-20 4:02
Vaclav_1-Mar-20 4:02 
GeneralRe: Bluetooth socket failures Pin
Vaclav_28-Feb-20 8:32
Vaclav_28-Feb-20 8:32 
QuestionRunning console apps on windows 7 Pin
Calin Negru23-Feb-20 20:07
Calin Negru23-Feb-20 20:07 
AnswerRe: Running console apps on windows 7 Pin
Victor Nijegorodov23-Feb-20 20:45
Victor Nijegorodov23-Feb-20 20:45 
GeneralRe: Running console apps on windows 7 Pin
Calin Negru23-Feb-20 21:22
Calin Negru23-Feb-20 21:22 
AnswerRe: Running console apps on windows 7 Pin
Richard MacCutchan23-Feb-20 20:59
mveRichard MacCutchan23-Feb-20 20:59 
GeneralRe: Running console apps on windows 7 Pin
Calin Negru23-Feb-20 21:21
Calin Negru23-Feb-20 21:21 
GeneralRe: Running console apps on windows 7 Pin
jsc4229-Feb-20 11:16
professionaljsc4229-Feb-20 11:16 
Questiongetting started with ASM, what compilers do you use? Pin
Calin Negru21-Feb-20 1:47
Calin Negru21-Feb-20 1:47 
AnswerRe: getting started with ASM, what compilers do you use? Pin
Richard MacCutchan21-Feb-20 1:52
mveRichard MacCutchan21-Feb-20 1:52 
GeneralRe: getting started with ASM, what compilers do you use? Pin
Calin Negru21-Feb-20 2:40
Calin Negru21-Feb-20 2:40 
GeneralRe: getting started with ASM, what compilers do you use? Pin
Richard MacCutchan21-Feb-20 3:54
mveRichard MacCutchan21-Feb-20 3: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.