PJSIP no audio on iPad - ios

I have been working on a SIP client for iOS using PJSIP. Everything works great on iPhone all the models. But on iPad and iPod Touch the audio is not heard from the speakers of the iPad or the iPod Touch. The code works great for iPhone speakers. Since iPad and iPod do not have earpiece no audio is coming out from the SIP call from the speakers. Anyone who can let me know what could be wrong with the iPad implementation ? Here is the code that might help:
// Start and register sip account
int startPjsip(char sipUser, char sipDomain, char* scheme, char* realm, char* username, int dataType, char* passwd, char* proxy, char* protocol)
{
pj_status_t status;
pj_log_set_level(5);
// Create pjsua first
status = pjsua_create();
if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);
// Init pjsua
{
// Init the config structure
pjsua_config cfg;
pjsua_config_default (&cfg);
cfg.cb.on_incoming_call = &on_incoming_call;
cfg.cb.on_call_media_state = &on_call_media_state;
cfg.cb.on_call_state = &on_call_state;
cfg.cb.on_reg_state = &on_reg_state;
// Init the logging config structure
pjsua_logging_config log_cfg;
pjsua_logging_config_default(&log_cfg);
log_cfg.console_level = 4;
// Init the pjsua
status = pjsua_init(&cfg, &log_cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
// If outbound proxy is required.
if (proxy) {
cfg.outbound_proxy_cnt = 1;
cfg.outbound_proxy[0] = pj_str(proxy);
}
}
if (strcasecmp(protocol, "UDP") == 0)
{
/* iOS version above iOS 4 do not support UDP in bakground. */
// Add UDP transport.
{
// Init transport config structure
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = 5060;
// Add UDP transport.
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
}
}
if (strcasecmp(protocol, "TCP") == 0)
{
// Add TCP transport.
{
// Init transport config structure
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = 5060;
// Add TCP transport.
status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
}
}
// Initialization is done, now start pjsua
status = pjsua_start();
if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);
// Register the account on local sip server
{
pjsua_acc_config cfg;
pjsua_acc_config_default(&cfg);
char sipId[MAX_SIP_ID_LENGTH];
sprintf(sipId, "sip:%s#%s", sipUser, sipDomain);
cfg.id = pj_str(sipId);
char regUri[MAX_SIP_REG_URI_LENGTH];
sprintf(regUri, "sip:%s", sipDomain);
cfg.reg_uri = pj_str(regUri);
// Add sip account credentials.
cfg.cred_count = 1;
cfg.cred_info[0].scheme = pj_str(scheme);
cfg.cred_info[0].realm = pj_str(realm);
cfg.cred_info[0].username = pj_str(username);
cfg.cred_info[0].data_type = dataType;
cfg.cred_info[0].data = pj_str(passwd);
status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
if (status != PJ_SUCCESS) error_exit("Error adding account", status);
}
return 0;
}
static void on_call_media_state(pjsua_call_id call_id)
{
pjsua_call_info ci;
pjsua_call_get_info(call_id, &ci);
if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
// When media is active, connect call to sound device.
pjsua_conf_connect(ci.conf_slot, 0);
pjsua_conf_connect(0, ci.conf_slot);
pjsua_conf_adjust_rx_level(0, 1);
pjsua_conf_adjust_tx_level(0, 1);
}
PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id,
(int)ci.state_text.slen,
ci.state_text.ptr));
}

Related

LWIP threads seems to block any other threads on my FREERTOS setup on a arty Z7

I am learning freertos and lwip on a Arty Z7.
I have managed to launch several tasks without problem but when I try to setup a lwip server to receive TCP packets, the server works perfectly but the other tasks won't continue their work.
So when I run the following code, the xil_printf of the "dumb_task" is writing correctly its message until the PHY autonegation is complete. Then, Nothing will happen from the dumb_task but the connection from the tcp port are accepted by the fpga. (I have commented by purpose the receive packet thread as it's changing nothing).
Do you have any ideas of what could be the problem?
Thank you!
Here is my code:
what is in my main file:
static sys_thread_t g_server_th_handle;
void dumb_task(void *p){
while(1){
xil_printf("dummy!\n");
vTaskDelay(10);
}
}
int main()
{
xTaskCreate (dumb_task, "TestTask", 512, NULL, 4, NULL);
g_server_th_handle = create_server_thread(2);
vTaskStartScheduler();
while(1);
return 0;
}
what is in a .cpp/.h file for the server:
static sys_thread_t g_server_thread_handle;
static int complete_nw_thread;
struct netif server_netif;
int g_server_tasks_priority = DEFAULT_THREAD_PRIO;
void setting_thread(void *p)
{
/* the mac address of the board. this should be unique per board */
u8_t mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 };
/* Add network interface to the netif_list, and set it as default */
if (!xemac_add(&server_netif, NULL, NULL, NULL, mac_ethernet_address,
PLATFORM_EMAC_BASEADDR)) {
xil_printf("Error adding N/W interface\r\n");
return;
}
netif_set_default(&server_netif);
/* specify that the network if is up */
netif_set_up(&server_netif);
/* start packet receive thread - required for lwIP operation */
sys_thread_new("xemacif_input_thread",
(void(*)(void*))xemacif_input_thread, &server_netif,
THREAD_STACKSIZE, g_server_tasks_priority);
complete_nw_thread = 1;
vTaskResume(g_server_thread_handle);
vTaskDelete(NULL);
}
void accept_loop()
{
int sock, new_sd;
int opt=1;
struct sockaddr_in address, remote;
int size;
// set up address to connect to
memset(&address, 0, sizeof(address));
if ((sock = lwip_socket(AF_INET, SOCK_STREAM, 0)) < 0) {
xil_printf("TCP server: Error creating Socket\r\n");
return;
}
address.sin_family = AF_INET;
address.sin_port = htons(TCP_CONN_PORT);
address.sin_addr.s_addr = INADDR_ANY;
if (bind(sock, (struct sockaddr *)&address, sizeof (address)) < 0) {
xil_printf("TCP server: Unable to bind to port %d\r\n",
TCP_CONN_PORT);
close(sock);
return;
}
ioctl(sock,FIONBIO,&opt);
if (listen(sock, 0) < 0) {
xil_printf("TCP server: tcp_listen failed\r\n");
close(sock);
return;
}
size = sizeof(remote);
xil_printf("Server set and listening\n\r");
for(;;) {
if ((new_sd = accept(sock, (struct sockaddr *)&remote,
(socklen_t *)&size)) > 0){
char *ip = inet_ntoa(((struct sockaddr_in*) &remote)->sin_addr);
gTCP_connection_count +=1;
xil_printf("New connection from %s. Number of client : %d\n\r",
ip,gTCP_connection_count);
/*sys_thread_new("TCP_recv thread",
tcp_recv_traffic, (void*)&new_sd,
TCP_SERVER_THREAD_STACKSIZE,
g_server_tasks_priority);*/
}
vTaskDelay(pdMS_TO_TICKS( 1UL ));
}
}
void server_thread(void *p)
{
// /* initialize lwIP before calling sys_thread_new */
lwip_init();
/* any thread using lwIP should be created using sys_thread_new */
sys_thread_new("nw_thread", setting_thread, NULL,
THREAD_STACKSIZE, g_server_tasks_priority);
/* Suspend Task until auto-negotiation is completed */
if (!complete_nw_thread){
vTaskSuspend(NULL);
}
assign_default_ip(&(server_netif.ip_addr), &(server_netif.netmask),
&(server_netif.gw));
print_ip_settings(&(server_netif.ip_addr), &(server_netif.netmask),
&(server_netif.gw));
/* start the application*/
accept_loop();
vTaskDelete(NULL);
return;
}
sys_thread_t create_server_thread(int priority){
g_server_tasks_priority = priority;
g_server_thread_handle = sys_thread_new("server_thread", server_thread, 0,
THREAD_STACKSIZE, priority );
return g_server_thread_handle;
}

iOS - AudioToolbox Memory leak

I want to implement an audio manager. But I got a memory leak.
I don't know why & what happen. Could someone help me?
I create a button, the button event just runs the playAudio with audio path. Then, I click the button, click, click, click, ..., click(many times).
The memory usage is increased. I try to close the audio file and clean the memory before each play time, but no use.
Please help or try to give some ideas how to achieve this. Thanks!
Much detail you could see my demo project in Github
UIView
- (void)viewDidLoad {
[super viewDidLoad];
// Create an audio manager
self.audio1 = [AudioPlayerManager new];
}
// This is a button click event
- (IBAction)actionAudioPlay:(id)sender {
NSString *path1 = [NSString stringWithFormat:#"%#", [[NSBundle
mainBundle] pathForResource:#"success-notification-
alert_A_major" ofType:#"wav"]];
[self.audio1 playAudio:path1];
}
AudioManager
Prepare define
static const UInt32 maxBufferSize = 0x10000;
static const UInt32 minBufferSize = 0x4000;
static const UInt32 maxBufferNum = 3;
Global Variable
AudioFileID _audioFile;
AudioStreamBasicDescription _dataFormat;
AudioQueueRef _queue;
UInt32 numPacketsToRead;
AudioStreamPacketDescription *packetDescs;
AudioQueueBufferRef buffers[maxBufferNum];
SInt64 packetIndex;
UInt32 maxPacketSize;
UInt32 outBufferSize;
My code
- (void)playAudio:(NSString *)audioFileName {
// Step 1: Open the audio file
OSStatus status = AudioFileOpenURL(
(__bridge CFURLRef _Nonnull)([NSURL
fileURLWithPath:audioPath]),
kAudioFileReadPermission,
0,
&_audioFile);
// Step 2: Read the meta-data of this audio file
UInt32 formatSize = sizeof(AudioStreamBasicDescription);
status = AudioFileGetProperty(audioFileID,
kAudioFilePropertyDataFormat, &formatSize, &_dataFormat);
// Step 3: Register the callback function
status = AudioQueueNewOutput(
&dataFormat,
BufferCallback,
(__bridge void * _Nullable)(self),
nil,
nil,
0,
&_queue
);
if (status != noErr) NSLog(#"AudioQueueNewOutput bitrate failed %d", status);
// Step 4: Read the package size
UInt32 size = sizeof(maxPacketSize);
AudioFileGetProperty(
audioFileID,
kAudioFilePropertyPacketSizeUpperBound,
&size,
&maxPacketSize);
if (status != noErr) NSLog(#"kAudioFilePropertyPacketSizeUpperBound failed %d", status);
if (dataFormat.mFramesPerPacket != 0) {
Float64 numPacketsPersecond = dataFormat.mSampleRate / dataFormat.mFramesPerPacket;
outBufferSize = numPacketsPersecond * maxPacketSize;
} else {
outBufferSize = (maxBufferSize > maxPacketSize) ? maxBufferSize : maxPacketSize;
}
if (outBufferSize > maxBufferSize &&
outBufferSize > maxPacketSize) {
outBufferSize = maxBufferSize;
} else {
if (outBufferSize < minBufferSize) {
outBufferSize = minBufferSize;
}
}
// Step 5: Calculate the package count
numPacketsToRead = outBufferSize / maxPacketSize;
// Step 6: Alloc AudioStreamPacketDescription buffers
packetDescs = (AudioStreamPacketDescription *)malloc(numPacketsToRead * sizeof (AudioStreamPacketDescription));
// Step 7: Reset the packet index
packetIndex = 0;
// Step 8: Allocate buffer
for (int i = 0; i < maxBufferNum; i++) {
// Step 8.1: allock the buffer
status = AudioQueueAllocateBuffer(
_queue,
outBufferSize,
&buffers[i]
);
if (status != noErr) NSLog(#"AudioQueueAllocateBuffer failed %d", status);
// Step 8.2: Fill the audio data to buffer
[self audioQueueOutputWithQueue:_queue
queueBuffer:buffers[i]];
}
// Step 9: Start
status = AudioQueueStart(_queue, nil);
if (status != noErr) NSLog(#"AudioQueueStart failed %d", status);
}
Audio queue output method
- (void)audioQueueOutputWithQueue:(AudioQueueRef)audioQueue
queueBuffer:(AudioQueueBufferRef)audioQueueBuffer {
OSStatus status;
// Step 1: load audio data
// If the packetIndex is out of range, the ioNumPackets will be 0
UInt32 ioNumBytes = outBufferSize;
UInt32 ioNumPackets = numPacketsToRead;
status = AudioFileReadPacketData(
_audioFile,
NO,
&ioNumBytes,
packetDescs,
packetIndex,
&ioNumPackets,
audioQueueBuffer->mAudioData
);
if (status != noErr) NSLog(#"AudioQueueSetParameter failed %d", status);
// Step 2: prevent load audio data failed
if (ioNumPackets <= 0) {
return;
}
// Step 3: re-assign the data size
audioQueueBuffer->mAudioDataByteSize = ioNumBytes;
// Step 4: fill the buffer to AudioQueue
status = AudioQueueEnqueueBuffer(
audioQueue,
audioQueueBuffer,
ioNumPackets,
packetDescs
);
if (status != noErr) NSLog(#"AudioQueueEnqueueBuffer failed %d", status);
// Step 5: Shift to followed index
packetIndex += ioNumPackets;
}
Callback function
static void BufferCallback(void *inUserData,AudioQueueRef inAQ,
AudioQueueBufferRef buffer) {
AudioPlayerManager *manager = (__bridge AudioPlayerManager *)inUserData;
[manager audioQueueOutputWithQueue:inAQ queueBuffer:buffer];
}
Close audio file
- (OSStatus)close:(AudioFileID)audioFileID {
OSStatus status = AudioFileClose( audioFileID );
if (status != noErr) NSLog(#"AudioFileClose failed %d", status);
return status;
}
Free Memory
- (void)freeMemory {
if (packetDescs) {
free(packetDescs);
}
packetDescs = NULL;
}
Finally, I find out the solution. I just kill out my queue.
All of memory are released. Share my method to everyone who has the same ticket.
- (void)playAudio:(NSString *)audioFileName {
// Add these code
if (_queue) {
AudioFileClose(_audioFile);
[self freeMemory];
AudioQueueStop(_queue, true);
AudioQueueDispose(_queue, true);
_queue = nil;
}
// the other code ...
}

I'm not able to reconnect to WiFi automatically after interruption in the router when using ESP8266

Here is my code to connect to a WiFi network using EPS8266. I connected a DHT sensor to ESP. I'm able to get data when there is no interruption if interruption occurs at the router I'm not getting sensor data and also I'm not able to reconnect to the WiFi network
static void wifi_task(void * pvParameters) {
uint8_t status = 0;
uint8_t retries = 30;
struct sdk_station_config config = {
.ssid = "CloveIOT",
.password = "CloveIOT",
};
printf("WiFi: connecting to WiFi\n\r");
sdk_wifi_set_opmode(STATION_MODE);
sdk_wifi_station_set_config( & config);
while (1) {
while ((status != STATION_GOT_IP) && (retries)) {
status = sdk_wifi_station_get_connect_status();
printf("%s: status = %d\n\r", __func__, status);
if (status == STATION_WRONG_PASSWORD) {
printf("WiFi: wrong password\n\r");
break;
} else if (status == STATION_NO_AP_FOUND) {
printf("WiFi: AP not found\n\r");
break;
} else if (status == STATION_CONNECT_FAIL) {
printf("WiFi: connection failed\r\n");
break;
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
--retries;
}
if (status == STATION_GOT_IP) {
printf("WiFi: Connected\n\r");
xSemaphoreGive(wifi_alive);
taskYIELD();
}
while ((status = sdk_wifi_station_get_connect_status()) == STATION_GOT_IP) {
xSemaphoreGive(wifi_alive);
taskYIELD();
}
printf("WiFi: disconnected\n\r");
sdk_wifi_station_disconnect();
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
I had the same issue, now I am using this WiFi connection method which works well.
Before using delay(1200); it did not work and stalled on WiFi.status() != WL_CONNECTED.
void connectWiFi() {
WiFi.disconnect();
delay(1200);
WiFi.mode(WIFI_STA);
Serial.println(F("connectWiFi"));
WiFi.begin(ssid, password);
// wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println(F(""));
Serial.print(F("Connected to "));
Serial.println(ssid);
Serial.print(F("IP address: "));
Serial.println(WiFi.localIP());
}

Audio queue works not as expected in iOS 10

Update
I resolved the problem in recording in iOS 10. After adding Audio Session configuration before starting recording, it works as normal. But playback hasn't been resolved.
Here's the solution:
NSError *error = nil;
// the param category depends what you need
BOOL ret = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if (!ret) {
NSLog(#"Audio session category setup failed");
return;
}
// don't forget to setActive NO when finishing recording
ret = [[AVAudioSession sharedInstance] setActive:YES error:&error];
if (!ret)
{
NSLog(#"Audio session activation failed");
return;
}
Original
I work in audio recording with audio queue service in iOS. I followed apple's official tutorial to realize the recording part and playback part. It was successfully tested in iOS 9.3 in emulator but failed in iOS 10.3.1 in real device iPad.
For the recording part, the callback function invokes AudioFileWritePackets to save the audio into a file (see the code below). In iOS 9, ioNumPackets always has a non-zero value but in iOS 10, it is always 0 during the first recording, and from the second time it becomes normal. That is, only from the second time the recording works.
Here's some code about recording:
Callback function:
static void AudioInputCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp * inStartTime, UInt32 inNumPackets, const AudioStreamPacketDescription * inPacketDescs) {
NSLog(#"Input callback called");
RecordState * aqData = (RecordState*)inUserData;
if (aqData->isRecording == 0) return;
if (inNumPackets == 0 && aqData->dataFormat.mBytesPerPacket != 0)
inNumPackets = inBuffer->mAudioDataByteSize / aqData->dataFormat.mBytesPerPacket;
NSLog(#"inNumPackets = %d", inNumPackets);
// handler the data
if (outputToMobile){
OSStatus res = AudioFileWritePackets(aqData->audioFile, false, inBuffer->mAudioDataByteSize, inPacketDescs, aqData->currentPacket, &inNumPackets, inBuffer->mAudioData);
if(res == noErr)
aqData->currentPacket += inNumPackets;
}else{
}
// after handling, re-enqueue de buffer into the queue
AudioQueueEnqueueBuffer(aqData->queue, inBuffer, 0, NULL);
}
Start record function:
-(void)startRecording{
[self setupAudioFormat:&recordState.dataFormat];
recordState.currentPacket = 0;
OSStatus status;
status = AudioQueueNewInput(&recordState.dataFormat, AudioInputCallback, &recordState, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &recordState.queue);
if (status == 0) {
UInt32 dataFormatSize = sizeof (recordState.dataFormat);
AudioQueueGetProperty (recordState.queue,kAudioQueueProperty_StreamDescription,&recordState.dataFormat,&dataFormatSize);
if (outputToMobile) {
[self createFile];
SetMagicCookieForFile(recordState.queue, recordState.audioFile);
}
DeriveBufferSize(recordState.queue, &recordState.dataFormat, 0.5, &recordState.bufferByteSize);
for (int i = 0; i < NUM_BUFFERS; i++) {
AudioQueueAllocateBuffer(recordState.queue, recordState.bufferByteSize, &recordState.buffers[i]);
AudioQueueEnqueueBuffer(recordState.queue, recordState.buffers[i], 0, NULL);
}
recordState.isRecording = true;
AudioQueueStart(recordState.queue, NULL);
}
}
For the playback part, the callback function invokes AudioFileReadPacketData to read the audio file (see the code below). As well, in iOS 9, ioNumPackets is always non-zero but in iOS 10, ioNumPackets is always always 0 so that nothing is output from iOS 10.
Here's some code about playback:
Callback function:
static void AudioOutputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer){
NSLog(#"Output callback called");
PlayState *aqData = (PlayState *)inUserData;
if (aqData->isPlaying == 0) return;
UInt32 numBytesReadFromFile;
UInt32 numPackets = aqData->numPacketsToRead;
AudioFileReadPacketData(aqData->audioFile, false, &numBytesReadFromFile, aqData->packetDesc, aqData->currentPacket, &numPackets, inBuffer->mAudioData);
NSLog(#"outNumPackets = %d", numPackets);
if (numPackets > 0) {
AudioQueueEnqueueBuffer(aqData->queue, inBuffer, aqData->packetDesc ? numPackets : 0, aqData->packetDesc);
aqData->currentPacket += numPackets;
} else {
AudioQueueStop(aqData->queue, false);
aqData->isPlaying = false;
}
}
Start playback function:
- (void)startPlaying{
playState.currentPacket = 0;
[self openFile];
UInt32 dataFormatSize = sizeof(playState.dataFormat);
AudioFileGetProperty(playState.audioFile, kAudioFilePropertyDataFormat, &dataFormatSize, &playState.dataFormat);
OSStatus status;
status = AudioQueueNewOutput(&playState.dataFormat, AudioOutputCallback, &playState, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &playState.queue);
if (status == 0) {
playState.isPlaying = true;
UInt32 maxPacketSize;
UInt32 propertySize = sizeof(maxPacketSize);
AudioFileGetProperty(playState.audioFile,kAudioFilePropertyPacketSizeUpperBound,&propertySize,&maxPacketSize);
DeriveBufferSize(playState.dataFormat, maxPacketSize, 0.5, &playState.bufferByteSize, &playState.numPacketsToRead);
bool isFormatVBR = (playState.dataFormat.mBytesPerPacket == 0 ||playState.dataFormat.mFramesPerPacket == 0);
if (isFormatVBR) {
playState.packetDesc = (AudioStreamPacketDescription*) malloc (playState.numPacketsToRead * sizeof(AudioStreamPacketDescription));
} else {
playState.packetDesc = NULL;
}
//Set a Magic Cookie for a Playback Audio Queue
MyCopyEncoderCookieToQueue(playState.audioFile, playState.queue);
for (int i = 0; i < NUM_BUFFERS; i++) {
AudioQueueAllocateBuffer(playState.queue, playState.bufferByteSize, &playState.buffers[i]);
playState.buffers[i]->mAudioDataByteSize = playState.bufferByteSize;
AudioOutputCallback(&playState, playState.queue, playState.buffers[i]);
}
Float32 gain = 10.0;
AudioQueueSetParameter(playState.queue, kAudioQueueParam_Volume, gain);
AudioQueueStart(playState.queue, NULL);
}
}
This kind of incompatibility really upsets me for several days. Free to ask me if you need more details. I hope someone could help me out. Thanks a lot.

iOS CFSocket crash on empty UDP packet

I am using a CFSocket configured for UDP to send data through wifi. The problem is that when I receive an empty UDP packet, the wifi suddenly stops working. I cant receive or send wnything anymore after that. Does anyone know what seems to be the problem? Here is my configuration and callback code:
void socketCallback(CFSocketRef cfSocket, CFSocketCallBackType type, CFDataRef address, const void *data, void *userInfo)
{
NSData * inputData = (__bridge NSData*)data;
NSUInteger inputDataCapacity = inputData.length * 2;
if(inputDataCapacity > minimalFrameSize*2){
//DO STH
}
}
-(void) initNetworkCommunication
{
CFSocketContext socketContext = {0, (__bridge void *)(self), NULL, NULL, NULL};
_cfSocket = CFSocketCreate(kCFAllocatorDefault, AF_INET, SOCK_DGRAM, IPPROTO_UDP, kCFSocketAcceptCallBack | kCFSocketDataCallBack, (CFSocketCallBack)socketCallback, &socketContext);
if ( _cfSocket == NULL) {
// NSLog(#"CfSocketCreate failed");
}
else {
if( _cfSocket ) {
_addrData = [Utils createIpAddressDataRef:COMM_INT_LISTENER_ADDR];
int flag = 1;
CFSocketNativeHandle socket_handle = (CFSocketNativeHandle)CFSocketGetNative(_cfSocket);
setsockopt(socket_handle, SOL_SOCKET, SO_BROADCAST, &flag, sizeof(flag));
//set address of the socket to listen to
CFSocketSetAddress (_cfSocket, _addrData);
_cfSource = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _cfSocket, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), _cfSource, kCFRunLoopDefaultMode);
CFRelease(_cfSource);
CFRelease(_cfSocket);
}
}
}
And sometimes after the wifi "crash" happens, I get an "EXC_BAD_ACCESS" when using CFSocketSendData.

Resources