void * consumer (void * arg) { THARG * carg; unsigned int tstatus = 0, ithread, Retries = 0; msg_block_t msg; queue_t *pr2cq; carg = (THARG *) arg; ithread = carg->thread_number; carg = (THARG *)arg; pr2cq = &r2cq_array[ithread]; while (carg->work_done < carg->work_goal && Retries < MAX_RETRY && !ShutDown) { /* Receive and display/process messages */ /* Try to receive the requested number of messages, * but allow for early system shutdown */ tstatus = q_get (pr2cq, &msg, sizeof(msg), Q_TIMEOUT); if (0 == tstatus) { if (DisplayMessages > 0) message_display (&msg); carg->work_done++; Retries = 0; } else { Retries++; } } return NULL; }
request_t * mock_server_receives_query (mock_server_t *server, const char *ns, mongoc_query_flags_t flags, uint32_t skip, uint32_t n_return, const char *query_json, const char *fields_json) { sync_queue_t *q; request_t *request; q = mock_server_get_queue (server); request = (request_t *) q_get (q, server->request_timeout_msec); if (request && !request_matches_query (request, ns, flags, skip, n_return, query_json, fields_json, false)) { request_destroy (request); return NULL; } return request; }
void * transmitter (void * arg) { /* Obtain multiple producer messages, combining into a single */ /* compound message for the receiver */ unsigned int tstatus = 0, im, Retries = 0; T2R_MSG_TYPE t2r_msg = {0}; msg_block_t p2t_msg; while (!ShutDown && !AllProduced) { t2r_msg.num_msgs = 0; /* pack the messages for transmission to the receiver */ im = 0; while (im < TBLOCK_SIZE && !ShutDown && Retries < MAX_RETRY && !AllProduced) { tstatus = q_get (&p2tq, &p2t_msg, sizeof(p2t_msg), Q_TIMEOUT); if (0 == tstatus) { memcpy (&t2r_msg.messages[im], &p2t_msg, sizeof(p2t_msg)); t2r_msg.num_msgs++; im++; Retries = 0; } else { /* Timed out. */ Retries++; } } tstatus = q_put (&t2rq, &t2r_msg, sizeof(t2r_msg), INFINITE); if (tstatus != 0) return NULL; } return NULL; }
void * receiver (void * arg) { /* Obtain compound messages from the transmitter and unblock them */ /* and transmit to the designated consumer. */ unsigned int tstatus = 0, im, ic, Retries = 0; T2R_MSG_TYPE t2r_msg; msg_block_t r2c_msg; while (!ShutDown && Retries < MAX_RETRY) { tstatus = q_get (&t2rq, &t2r_msg, sizeof(t2r_msg), Q_TIMEOUT); if (tstatus != 0) { /* Timeout - Have the producers shut down? */ Retries++; continue; } Retries = 0; /* Distribute the packaged messages to the proper consumer */ im = 0; while (im < t2r_msg.num_msgs) { memcpy (&r2c_msg, &t2r_msg.messages[im], sizeof(r2c_msg)); ic = r2c_msg.destination; /* Destination consumer */ tstatus = q_put (&r2cq_array[ic], &r2c_msg, sizeof(r2c_msg), INFINITE); if (0 == tstatus) im++; } } return NULL; }
void* consumeBuff(void *threadConsumer) { /* consumeBuff consume every character in circular buffer with delay 3s */ /*** CHILD PROCESS ***/ int i = 1; while (true) { /* Call q_get */ Byte *ch = q_get(rxq); if ((ch != NULL) && ((*ch>=32) || (*ch==CR) || (*ch==LF) || (*ch==Endfile))) { // Consume char, check if valid if (*ch==CR) printf("Mengkonsumsi byte ke-%d: 'Carriage Return'\n", i); else if (*ch==LF) printf("Mengkonsumsi byte ke-%d: 'Line Feed'\n", i); else if (*ch==Endfile) printf("Mengkonsumsi byte ke-%d: 'End of File'\n", i); else printf("Mengkonsumsi byte ke-%d: '%c'\n", i, *ch); ++i; if(rxq->count <= LOWERLIMIT && !xon_active) { /* Sending XON */ xon_active = true; xonxoff = XON; printf("Buffer < maximum lowerlimit. Mengirim XON.\n"); if (sendto(sockfd, &xonxoff, 1, 0, (struct sockaddr *)&remaddr, addrlen) < 0) { perror("Failed send response"); exit(1); } } /* Can introduce some delay here. */ sleep(3); } } }
ds_cmd_type *ds_get_cmd_buf( void ) { ds_cmd_type *cmd_ptr; /* Pointer to command */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /*------------------------------------------------------------------------- Get a command buffer from the free command queue. -------------------------------------------------------------------------*/ if( (cmd_ptr = q_get( &dsi_cmd_free_q )) == NULL ) { /*----------------------------------------------------------------------- No free command buffers available, log an error. -----------------------------------------------------------------------*/ ERR( "No items on DS Task free cmd q", 0, 0, 0 ); } /*------------------------------------------------------------------------- Note that the cmd_ptr may be NULL if there were no free command buffers available. The calling task must either handle the NULL return value or ERR_FATAL. -------------------------------------------------------------------------*/ return( cmd_ptr ); } /* ds_get_cmd_buf() */
request_t * mock_server_receives_request (mock_server_t *server) { sync_queue_t *q; q = mock_server_get_queue (server); return (request_t *) q_get (q, server->request_timeout_msec); }
#include "mqueue.h" int mq_init(mqueue *q) { /*{{{*/ q_init(&q->q); if (q->flag == 0) { pthread_mutex_init(&q->m, NULL); pthread_cond_init(&q->c, NULL); } q->flag = 1; } /*}}}*/ int mq_post(mqueue *q, int data0, void *data1) { /*{{{*/ pthread_mutex_lock(&q->m); q_post(&q->q, data0, data1); pthread_cond_broadcast(&q->c); pthread_mutex_unlock(&q->m); } /*}}}*/ int mq_get(mqueue *q, int *data0, void **data1) { /*{{{*/ pthread_mutex_lock(&q->m); int r = q_get(&q->q, data0, data1); pthread_mutex_unlock(&q->m); return r; } /*}}}*/ int mq_get_wait(mqueue *q, int *data0, void **data1) { /*{{{*/ int r = 0; pthread_mutex_lock(&q->m); while ((r = q_get(&q->q, data0, data1)) == 0) { pthread_cond_wait(&q->c, &q->m); } pthread_mutex_unlock(&q->m); return r; } /*}}}*/
int assign(pfac f){ int ret; pnode p; pthread_mutex_lock(&f->mutex); while(!q_get(&f->qwait,&p)){ pthread_cond_wait(&f->cond,&f->mutex); } ret=p->fd; free(p); pthread_mutex_unlock(&f->mutex); return ret; }
void* childprocess(void *threadArgs){ while (true) { /* Call q_get */ Byte Ce; Byte * consumer = q_get(rxq,&Ce); if (consumer != NULL){ printf("Mengkonsumsi byte ke-%d: %u\n",++count_consumed,(unsigned int)consumer ); } /* Can introduce some delay here. */ sleep(1); } }
void *childRProcess(void *threadid) { Byte *data, *current = NULL; while (1) { current = q_get(rxq, data); // if end file, quit the process /*if (current != NULL && endFileReceived) break;*/ // introduce some delay here sleep(2); } pthread_exit(NULL); }
void* threadChild(void *arg) { /* Child Thread */ Byte *chck; /* Sampai program diakhiri, konsumsi terus byte yang ada pada buffer*/ while ((parentExit == 0) || (consumedByte != receivedByte)) { chck = q_get(sockfd, &buffer); if ( chck != NULL ) { consumedByte++; printf("Mengkonsumsi byte ke-%d: '%s'\n", consumedByte, chck); } usleep(DELAY * 1000); } return NULL; }
request_t *mock_server_receives_kill_cursors (mock_server_t *server, int64_t cursor_id) { sync_queue_t *q; request_t *request; q = mock_server_get_queue (server); request = (request_t *) q_get (q, server->request_timeout_msec); if (request && !request_matches_kill_cursors (request, cursor_id)) { request_destroy (request); return NULL; } return request; }
void* mainThread(void* threadArgs){ pthread_mutex_lock(&lock); while(1){ if(q_get(rxq,¤tByte) != NULL){ if(isValidChar(currentByte)){ printf("Mengkonsumsi byte ke-%d: ‘%c’\n", countCnsmdBytes++, currentByte); } else if (currentByte == Endfile){ printf("end-of-file\n" ); exit(0); } } usleep(DELAY*3000); } pthread_mutex_unlock(&lock); return NULL; }
void decoder_data_pull(decoder_handle _handle, float **_buffer, unsigned int *_len, unsigned int *_frate) { struct decoder_handle_struct *handle = (struct decoder_handle_struct *)_handle; struct decoder_buffer_type *buf; buf = q_get(handle->queue); if(!buf) { *_buffer = NULL; *_len = 0; *_frate = 0; printf("Error in getting input\n"); } else { *_buffer = buf->buffer; *_len = buf->len; *_frate = buf->frate; } free(buf); }
/*=========================================================================== FUNCTION DSSICMP_CLOSE() DESCRIPTION This function is the ICMP specific dss_close() function. It simply sets the socket state to DSSOCKI_NULL and frees up the socket control block and related data structures. DEPENDENCIES None. RETURN VALUE DSS_SUCCESS on success; DSS_ERROR otherwise. SIDE EFFECTS None. ===========================================================================*/ extern sint15 dssicmp_close ( struct scb_s* scb_ptr, /* Ptr to socket control block for the socket */ sint15 *dss_errno /* error condition value */ ) { struct icmp_cb *icmp_cb_ptr; /* ICMP protocol control block */ dsm_item_type *item_ptr; /* temporary item ptr */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /*------------------------------------------------------------------------- Assert that a valid ptr to a dss_errno variable was specified - Prevents dereferencing of NULL ptrs. -------------------------------------------------------------------------*/ if (dss_errno == NULL) { ASSERT(0); return(DSS_ERROR); } *dss_errno = DSS_SUCCESS; icmp_cb_ptr = (struct icmp_cb *) scb_ptr->protocol_ctl_blk.icb; /*------------------------------------------------------------------------- Free the receive queue for the ICMP control block. ------------------------------------------------------------------------*/ while(( item_ptr = (dsm_item_type *) q_get( &(icmp_cb_ptr->rcvq))) != NULL) { dsm_free_packet(&item_ptr); } /*------------------------------------------------------------------------- Free the ICMP control block. ------------------------------------------------------------------------*/ dssicmpi_free_icmp_cb(icmp_cb_ptr); /*------------------------------------------------------------------------- Free the socket control block. ------------------------------------------------------------------------*/ dssocki_freescb(scb_ptr); return (DSS_SUCCESS); } /* dssicmp_close () */
request_t * mock_server_receives_command (mock_server_t *server, const char *database_name, mongoc_query_flags_t flags, const char *command_json, ...) { va_list args; char *formatted_command_json = NULL; char *ns; sync_queue_t *q; request_t *request; va_start (args, command_json); if (command_json) { formatted_command_json = bson_strdupv_printf (command_json, args); } va_end (args); ns = bson_strdup_printf ("%s.$cmd", database_name); q = mock_server_get_queue (server); request = (request_t *) q_get (q, server->request_timeout_msec); if (request && !request_matches_query (request, ns, flags, 0, 1, formatted_command_json, NULL, true)) { request_destroy (request); request = NULL; } bson_free (formatted_command_json); bson_free (ns); return request; }
/*=========================================================================== FUNCTION RFLLCB_GET_EVENT_BUFFER DESCRIPTION Gets an event structure buffer that must be used to register a sequence of call back events. Buffer is freed by making a call to rfllcb_register_events() with the buffer pointer as input. DEPENDENCIES A buffer should only be allocated when getting ready to register events with a call to rfllcb_register_events(). RETURN VALUE Pointer to event structure. SIDE EFFECTS An assert is thrown if no event buffers are available. ===========================================================================*/ rfllcb_struct_type* rfllcb_get_event_buffer( void ) { rfllcb_struct_type *rtn_ptr; /* Get buffer from free queue. */ rtn_ptr = (rfllcb_struct_type*) q_get( &free_que ); /* Throw assert if queue empty. This implies the number of call backs supported must be increased. */ ASSERT( rtn_ptr != NULL ); /* Make sure we stop here even if ASSERTs are not enabled within development builds, which seems to be common practice. */ if ( rtn_ptr == NULL ) /*lint !e774, Boolean within 'if' always evaluates to False */ { ERR_FATAL("Need to increase number call backs supported.", 0, 0, 0 ); } return rtn_ptr; } /* rfllcb_get_event_buffer() */
request_t * mock_server_receives_delete (mock_server_t *server, const char *ns, mongoc_remove_flags_t flags, const char *selector_json) { sync_queue_t *q; request_t *request; q = mock_server_get_queue (server); request = (request_t *) q_get (q, server->request_timeout_msec); if (request && !request_matches_delete (request, ns, flags, selector_json)) { request_destroy (request); return NULL; } return request; }
request_t * mock_server_receives_bulk_insert (mock_server_t *server, const char *ns, mongoc_insert_flags_t flags, int n) { sync_queue_t *q; request_t *request; q = mock_server_get_queue (server); request = (request_t *) q_get (q, server->request_timeout_msec); if (request && !request_matches_bulk_insert (request, ns, flags, n)) { request_destroy (request); return NULL; } return request; }
float *spectgen_pull(spectgen_handle _handle) { struct spectgen_struct *handle = (struct spectgen_struct *)_handle; return q_get(&handle->queue); }
/*=========================================================================== FUNCTION DSSICMP_READ() DESCRIPTION Reads 'nbytes' bytes into the buffer from the ICMP transport. Fills in address structure with values from who sent the data in fromaddr. This function asserts that fromaddr is not NULL. This function is the ICMP specific dss_recvfrom() DEPENDENCIES None. PARAMETERS struct scb_s* scb_ptr - Ptr to socket control block for the socket void *buffer - user buffer from which to copy the data uint16 nbytes - number of bytes app wants to read struct sockaddr_in *fromaddr - source address sint15 *dss_errno - error condition value RETURN VALUE n - the number of bytes to be written, which could be less than the number of bytes specified. On error, return DSS_ERROR and places the error condition value in *dss_errno. Errno Values ------------ DS_EWOULDBLOCK operation would block SIDE EFFECTS None. ===========================================================================*/ extern sint15 dssicmp_read ( struct scb_s* scb_ptr, /* Ptr to socket control block for the socket */ struct iovec * iov, /* user buffer from which to copy the data */ uint16 iovcount, /* length of the iovec array */ struct sockaddr_in *fromaddr, /* source address */ sint15 *dss_errno /* error condition value */ ) { struct icmp_cb *icmp_cb_ptr; /* ICMP protocol control block */ dsm_item_type *item_ptr; /* ptr to head of dsm memory pool items */ uint16 cnt=0; /* tmp # of bytes retrieved */ uint16 bytes_read =0; /* # of bytes to read from rcvq */ uint16 read_cnt=0; /* # of bytes read in each iteration */ uint16 payload_len=0; /* packet length */ int i; /* local loop index */ uint16 bytes_requested; /* # of bytes requested in each iteration */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ MSG_LOW("In dssicmp_read()", 0, 0, 0); /*------------------------------------------------------------------------- Ensure that the "from address" is not NULL. This function fills in this structure, thus, needs to ASSERT against dereferencing a NULL pointer. ------------------------------------------------------------------------*/ ASSERT( fromaddr != NULL); /*------------------------------------------------------------------------- Set the socket and ICMP control block pointers, and set the family to AF_INET. -------------------------------------------------------------------------*/ icmp_cb_ptr = scb_ptr->protocol_ctl_blk.icb; fromaddr->sin_family = AF_INET; MSG_LOW("ICMP CB pointer successfully set", 0, 0, 0); /*------------------------------------------------------------------------- Check if there is anything in the ICMP receive queue. If not, return DS_EWOULDBLOCK. -------------------------------------------------------------------------*/ if ( (item_ptr = (dsm_item_type *) q_get( (&(icmp_cb_ptr->rcvq)))) == NULL) { MSG_LOW("Nothing on ICMP revq", 0, 0, 0); *dss_errno = DS_EWOULDBLOCK; return (DSS_ERROR); } MSG_LOW("There is indeed something on the ICMP rcvq", 0, 0, 0); /*------------------------------------------------------------------------- Extract the payload length, server's IP address and store in fromaddr. ASSERT that bytes to read, are equal to the number of bytes pulled up. The port field will be undefined in the fromaddr structure returned to the application. -------------------------------------------------------------------------*/ cnt = dsm_pullup(&item_ptr, &(fromaddr->sin_addr), sizeof(fromaddr->sin_addr)); ASSERT( cnt == sizeof(fromaddr->sin_addr) ); MSG_MED("extracted server's IP %x", fromaddr->sin_addr.s_addr, 0, 0); /*------------------------------------------------------------------------- Extract the number of bytes which the application wants to read. -------------------------------------------------------------------------*/ payload_len = dsm_length_packet( item_ptr ); for(i=0;i< iovcount && payload_len > 0 ; i++) { /*----------------------------------------------------------------------- Extract the number of bytes which the application wants to read. -----------------------------------------------------------------------*/ bytes_requested = MIN( payload_len, iov[i].iov_len); if(bytes_requested > 0) { read_cnt = dsm_pullup( &(item_ptr), iov[i].iov_base, bytes_requested); } /*----------------------------------------------------------------------- ASSERT that we read the expected number of bytes from the buffer. -----------------------------------------------------------------------*/ ASSERT(read_cnt == bytes_requested); payload_len -= read_cnt; bytes_read += read_cnt; read_cnt = 0; } if (payload_len > 0 ) { ERR("User provided buffer is smaller than received datagram (%d bytes)", bytes_read + payload_len, 0, 0); } MSG_LOW("Successfully read nbytes of data in DSSICMP_READ", 0, 0, 0); /*------------------------------------------------------------------------- Free the packet in dsm buffer. -------------------------------------------------------------------------*/ dsm_free_packet ( &item_ptr ); MSG_LOW("Packet is successfully freed in DSSICMP_READ", 0, 0, 0); /*------------------------------------------------------------------------- Check if there are any remaining ICMP packets in the receive queue. Set the readable flag to FALSE, if there are no remaining ICMP packets. Access to global SCB array item is protected through INTLOCK()/INTFREE(). -------------------------------------------------------------------------*/ if ( (item_ptr = (dsm_item_type *) q_check( &(icmp_cb_ptr->rcvq))) == NULL) { INTLOCK(); scb_ptr->data_available = FALSE; INTFREE(); } /*------------------------------------------------------------------------- Convert the server IP address into the Network byte order. Note, only the IP address is in host order, the port number is not. -------------------------------------------------------------------------*/ (fromaddr->sin_addr).s_addr = dss_htonl( (fromaddr->sin_addr).s_addr); /*------------------------------------------------------------------------- Return the number of bytes read from the buffer. -------------------------------------------------------------------------*/ MSG_LOW("DONE ICMPREAD", 0, 0, 0); return ( (sint15) bytes_read); } /* dssudp_read() */
/*=========================================================================== FUNCTION Q_LINEAR_DELETE DESCRIPTION Given a comparison function, this function traverses the elements in a queue, calls the compare function, and returns a pointer to the current element being compared if the user passed compare function returns non zero. In addition, the item will be removed from the queue. The user compare function should return 0 if the current element is not the element in which the compare function is interested. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. The user's queue elements must have q_link_type as the first element of the queued structure. The user's compare function will be passed NULL for the compare value. RETURN VALUE None SIDE EFFECTS None. ===========================================================================*/ void q_linear_delete( q_type *q_ptr, q_compare_func_type compare_func, void *param, q_action_func_type action_func ) { q_generic_item_type *item_ptr = NULL; /* Used in the traversal to point to the current item */ q_generic_item_type *prev_ptr = NULL; /* Used in the traversal to point to the item previous to ** the current item. This makes removing the current item ** a constant time operation */ /* User must provide a compare function, otherwise, this is ** meaningless. */ if( compare_func == NULL ) { return; } q_lock( q_ptr ); /* item_ptr points to the first item on the list */ item_ptr = (q_generic_item_type*)q_check( q_ptr ); prev_ptr = NULL; while( item_ptr != NULL ) { if( compare_func( item_ptr, NULL ) != 0 ) { /* Remove the item */ if( prev_ptr != NULL ) { /* Remove from the middle or tail */ prev_ptr->link.next_ptr = item_ptr->link.next_ptr; item_ptr->link.next_ptr = NULL; } else { /* Remove from the head */ q_get( q_ptr ); } /* Call the action function if there is one */ if( action_func ) { action_func( item_ptr, param ); } break; } /* Move on to the next item */ prev_ptr = item_ptr; item_ptr = (q_generic_item_type*)q_next( q_ptr, &item_ptr->link ); } /* END while traversing the queue */ q_free( q_ptr ); return; } /* END q_linear_delete */
/*=========================================================================== FUNCTION DSI_PROCESS_CMDS DESCRIPTION This function de-queues commands from the Data Services Task's command queue, and dispataches commands to the appropriate entity for further processing, if necessary. Commands are de-queued until the command queue is empty. DEPENDENCIES This function should be called when the DS_CMD_Q_SIG is set. RETURN VALUE None SIDE EFFECTS None ===========================================================================*/ void dsi_process_cmds( void ) { ds_cmd_type *cmd_ptr; /* Pointer to command */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /*------------------------------------------------------------------------- Get commands from the command queue until the queue is empty. For each command received, dispatch the command to the appropriate sub-task. -------------------------------------------------------------------------*/ while( (cmd_ptr = (ds_cmd_type *)q_get( &dsi_cmd_q )) != NULL ) { switch( cmd_ptr->hdr.cmd_id ) { /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3G Dsmgr Commands - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ case DS_CM_CALL_END_CMD: case DS_CM_CALL_INCOM_CMD: case DS_CM_CALL_CONNECTED_CMD: case DS_CM_CALL_SETUP_CMD: case DS_CM_CALL_CONF_CMD: #ifdef FEATURE_WCDMA #error code not present #endif /* FEATURE_WCDMA */ case DS_TIMER_EXPIRED_CMD: case DS_COMPLETE_LL_CONNECT_CMD: case DS_COMPLETE_LL_DISCONNECT_CMD: case DS_INITIATE_CALL_CMD: case DS_RELEASE_CALL_CMD: case DS_CM_SS_SRV_CHG_CMD: ds3g_process_cmds( cmd_ptr ); break; #ifndef FEATURE_DATA_STRIP_ATCOP /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3G SIOLIB Commands - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ case DS_RDM_OPEN_CMD: case DS_RDM_CLOSE_CMD: case DS_ENTER_ONLINE_CMD_TX_FLUSH_CMD: case DS_ENTER_ONLINE_CMD_NO_TX_FLUSH_CMD: case DS_ENTER_ONLINE_DATA_TX_FLUSH_CMD: case DS_ENTER_ONLINE_DATA_NO_TX_FLUSH_CMD: case DS_COMPLETE_ONLINE_CMD_SWITCH_CMD: case DS_COMPLETE_ONLINE_DATA_SWITCH_CMD: ds3g_siolib_process_cmds( cmd_ptr ); break; #endif #if ((defined(FEATURE_WCDMA) && defined(FEATURE_DATA_WCDMA_CS)) || \ (defined(FEATURE_GSM) && defined(FEATURE_DATA_GCSD))) #error code not present #endif /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ATCoP Commands - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #ifndef FEATURE_DATA_STRIP_ATCOP case DS_AT_CM_CALL_CMD: case DS_AT_CM_CALL_INFO_CMD: case DS_AT_TIMER_EXPIRED_CMD: case DS_AT_STATUS_CMD: #if defined(FEATURE_WCDMA) || defined(FEATURE_GSM) #error code not present #endif /* defined(FEATURE_WCDMA) || defined(FEATURE_GSM) */ #if defined(FEATURE_ETSI_PBM) || defined(FEATURE_DSAT_CDMA_PBM) case DS_AT_PBM_CB_CMD: #endif /* defined(FEATURE_ETSI_PBM) || defined(FEATURE_DSAT_CDMA_PBM) */ #if defined(FEATURE_ETSI_SMS) || defined(FEATURE_CDMA_SMS) case DS_AT_SMS_ERR_CMD: case DS_AT_SMS_MSG_CMD: case DS_AT_SMS_CFG_CMD: case DS_AT_SMS_ABT_CMD: #endif /* defined(FEATURE_ETSI_SMS) || defined(FEATURE_CDMA_SMS) */ #ifdef FEATURE_DATA_GCSD_FAX #error code not present #endif /* FEATURE_DATA_GCSD_FAX */ #ifdef FEATURE_DATA_ETSI_SUPSERV case DS_AT_CM_SUPS_CMD: case DS_AT_CM_SUPS_INFO_CMD: #endif /* FEATURE_DATA_ETSI_SUPSERV */ #ifdef FEATURE_MMGSDI case DS_AT_MMGSDI_INFO_CMD: #endif /* FEATURE_MMGSDI */ dsat_process_async_cmd( cmd_ptr ); break; #endif /* FEATURE_DATA_STRIP_ATCOP */ #ifdef FEATURE_UIM_SUPPORT_3GPD case DS_AT_GSDI_INFO_CMD: #ifdef FEATURE_DATA_STRIP_ATCOP (void)dsatprofile_gsdi_event_handler(DSAT_CMD,cmd_ptr); #else (void)dsatme_gsdi_event_handler(DSAT_CMD,cmd_ptr); #endif break; #endif /*FEATURE_UIM_SUPPORT_3GPD*/ #ifdef FEATURE_DATA_IS707 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IS707-PKT Commands - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ case DS_707_PKT_PZID_CHANGE_CMD: case DS_707_PKT_SID_CHANGE_CMD: case DS_707_PKT_NID_CHANGE_CMD: case DS_707_PKT_CTA_TIMER_EXPIRED_CMD: case DS_707_PKT_HOLDDOWN_TIMER_EXPIRED_CMD: case DS_707_PKT_PZID_DELAY_TIMER_EXPIRED_CMD: case DS_707_PKT_PZID_HYSTERESIS_TIMER_EXPIRED_CMD: case DS_707_PKT_PHYS_LINK_UP_CMD: case DS_707_PKT_PHYS_LINK_DOWN_CMD: case DS_707_PKT_IFACE_UP_CMD: case DS_707_PKT_IFACE_DOWN_CMD: case DS_707_PKT_IFACE_DOWN_IND_CBACK_CMD: case DS_707_PKT_IFACE_UP_IND_CBACK_CMD: case DS_707_PKT_IFACE_ROUTEABLE_IND_CBACK_CMD: case DS_707_TOGGLE_QNC_ENABLE_CMD: case DS_707_PKT_PZID_HYS_DATA_READY_CMD: case DS_707_PKT_PZID_HYS_SDB_DATA_CMD: ds707_pkt_process_cmd(cmd_ptr); break; /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - RMSM IS707-PKT Commands - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #ifndef FEATURE_DATA_STRIP_ATCOP case DS_707_RMSM_RM_WANTS_PKT_CALL_CMD: case DS_707_RMSM_RM_IFACE_DOWN_CMD: case DS_707_RMSM_UM_IFACE_DOWN_CMD: case DS_707_RMSM_UM_PHYS_LINK_UP_CMD: case DS_707_RMSM_UM_PHYS_LINK_DOWN_CMD: case DS_707_RMSM_UM_PPP_DOWN_CMD: #ifdef FEATURE_DS_MOBILE_IP case DS_707_RMSM_RM_PPP_UP_CMD: case DS_707_RMSM_UM_MIP_UP_CMD: case DS_707_RMSM_UM_MIP_DOWN_CMD: #endif /* FEATURE_DS_MOBILE_IP */ ds707_rmsm_process_cmd(cmd_ptr); break; #endif #ifndef FEATURE_ASYNC_DATA_NOOP /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IS707-Async Commands - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ case DS_707_ASYNC_IFACE_BRING_UP_CMD: case DS_707_ASYNC_IFACE_TEAR_DOWN_CMD: case DS_707_ASYNC_PHYS_LINK_TEAR_DOWN_CMD: case DS_707_ASYNC_PTCL_OPENING_TIMER_EXPIRED_CMD: case DS_707_ASYNC_PTCL_OPENED_CMD: case DS_707_ASYNC_PTCL_CLOSED_CMD: case DS_707_ASYNC_ATZ_CMD: ds707_async_process_cmd(cmd_ptr); break; #endif /*FEATURE_ASYNC_DATA_NOOP*/ #endif /* FEATURE_DATA_IS707 */ #if defined(FEATURE_DATA_WCDMA_PS) || defined(FEATURE_GSM_GPRS) #error code not present #endif /* FEATURE_DATA_WCDMA_PS || FEATURE_GSM_GPRS */ #if defined(FEATURE_DATA_WCDMA_PS) || defined(FEATURE_GSM_GPRS) #error code not present #endif /* FEATURE_DATA_WCDMA_PS || FEATURE_GSM_GPRS */ #ifdef FEATURE_HDR #error code not present #endif /* FEATURE_HDR */ default: ERR_FATAL( "Invalid DS task command: %d", cmd_ptr->hdr.cmd_id, 0,0); } /* switch */ /*----------------------------------------------------------------------- Return the command buffer to the free command queue. -----------------------------------------------------------------------*/ q_put( &dsi_cmd_free_q, &cmd_ptr->hdr.link ); } /* while */ } /* dsi_process_cmds() */
#include "mqueue.h" int mq_init(mqueue *q) { /*{{{*/ q_init(&q->q); if (q->flag == 0) { pthread_mutex_init(&q->m, NULL); pthread_cond_init(&q->c, NULL); } q->flag = 1; } /*}}}*/ int mq_post(mqueue *q, int data0, void *data1) { /*{{{*/ pthread_mutex_lock(&q->m); q_post(&q->q, data0, data1); pthread_cond_broadcast(&q->c); pthread_mutex_unlock(&q->m); } /*}}}*/ int mq_get(mqueue *q, int *data0, void **data1) { /*{{{*/ pthread_mutex_lock(&q->m); int r = q_get(&q->q, data0, data1); pthread_mutex_unlock(&q->m); return r; } /*}}}*/
static void * worker_thread (void *data) { worker_closure_t *closure = (worker_closure_t *) data; mock_server_t *server = closure->server; mongoc_stream_t *client_stream = closure->client_stream; mongoc_buffer_t buffer; mongoc_rpc_t *rpc = NULL; bool handled; bson_error_t error; int32_t msg_len; sync_queue_t *requests; sync_queue_t *replies; request_t *request; mongoc_array_t autoresponders; ssize_t i; autoresponder_handle_t handle; reply_t *reply; #ifdef MONGOC_ENABLE_SSL bool ssl; #endif ENTRY; /* queue of client replies sent over this worker's connection */ replies = q_new (); #ifdef MONGOC_ENABLE_SSL mongoc_mutex_lock (&server->mutex); ssl = server->ssl; mongoc_mutex_unlock (&server->mutex); if (ssl) { if (!mongoc_stream_tls_handshake_block (client_stream, "localhost", TIMEOUT, &error)) { mongoc_stream_close (client_stream); mongoc_stream_destroy (client_stream); RETURN (NULL); } } #endif _mongoc_buffer_init (&buffer, NULL, 0, NULL, NULL); _mongoc_array_init (&autoresponders, sizeof (autoresponder_handle_t)); again: /* loop, checking for requests to receive or replies to send */ bson_free (rpc); rpc = NULL; if (_mongoc_buffer_fill (&buffer, client_stream, 4, 10, &error) > 0) { assert (buffer.len >= 4); memcpy (&msg_len, buffer.data + buffer.off, 4); msg_len = BSON_UINT32_FROM_LE (msg_len); if (msg_len < 16) { MONGOC_WARNING ("No data"); GOTO (failure); } if (_mongoc_buffer_fill (&buffer, client_stream, (size_t) msg_len, -1, &error) == -1) { MONGOC_WARNING ("%s():%d: %s", BSON_FUNC, __LINE__, error.message); GOTO (failure); } assert (buffer.len >= (unsigned) msg_len); /* copies message from buffer */ request = request_new (&buffer, msg_len, server, client_stream, closure->port, replies); memmove (buffer.data, buffer.data + buffer.off + msg_len, buffer.len - msg_len); buffer.off = 0; buffer.len -= msg_len; mongoc_mutex_lock (&server->mutex); _mongoc_array_copy (&autoresponders, &server->autoresponders); mongoc_mutex_unlock (&server->mutex); test_suite_mock_server_log ("%5.2f %hu -> %hu %s", mock_server_get_uptime_sec (server), closure->port, server->port, request->as_str); /* run responders most-recently-added-first */ handled = false; for (i = server->autoresponders.len - 1; i >= 0; i--) { handle = _mongoc_array_index (&server->autoresponders, autoresponder_handle_t, i); if (handle.responder (request, handle.data)) { /* responder destroyed request and enqueued a reply in "replies" */ handled = true; request = NULL; break; } } if (!handled) { /* pass to the main thread via the queue */ requests = mock_server_get_queue (server); q_put (requests, (void *) request); } } if (_mock_server_stopping (server)) { GOTO (failure); } reply = q_get (replies, 10); if (reply) { _mock_server_reply_with_stream (server, reply, client_stream); _reply_destroy (reply); } if (_mock_server_stopping (server)) { GOTO (failure); } GOTO (again); failure: _mongoc_array_destroy (&autoresponders); _mongoc_buffer_destroy (&buffer); mongoc_stream_close (client_stream); mongoc_stream_destroy (client_stream); bson_free (rpc); bson_free (closure); _mongoc_buffer_destroy (&buffer); while ((reply = q_get_nowait (replies))) { _reply_destroy (reply); } q_destroy (replies); RETURN (NULL); }
void* threadChild(void *arg) { /* Child Thread */ char* chck; int i = 0; int length = 0; int start = 0; bool canBeConsumed = false; Frame Ftemp[100]; int temp[100]; int tempLength = 0; /* Sampai program diakhiri, konsumsi terus byte yang ada pada buffer*/ while (parentExit != 1) { chck = q_get(sockfd, &buffer); if ( chck != NULL ) { Frame F; F.GetDecompiled(chck); // Set frame number dan checksum pada Response R.SetNumber(F.GetNumber()); R.SetChecksum(F.GetChecksum()); // Checks checksum cout << F.GenerateChecksumCRC(chck) << endl; cout << F.GetChecksum() << endl; if ( F.GenerateChecksumCRC(chck) != F.GetChecksum() ) { printf("Invalid Checksum. Send NAK.\n"); R.SetType(NAK); --receivedByte; } else { R.SetType(ACK); } int num = R.GetNumber(); if (tempLength < ( R.GetNumber() + 1 )) { tempLength = R.GetNumber() + 1; } if (R.GetType() == ACK) { if (num < i) { temp[num] = num; Ftemp[num] = F; } else { temp[i] = i; Ftemp[i] = F; if ( i > 0 ) { length++; } } } else { //NAK if (num < i) temp[num] = -1; else temp[i] = -1; } int j = Rw.getLength(); while ( ( temp[j] != -1 ) && ( j < tempLength ) ) { Rw.insertFrame(Ftemp[j], j); cout << "Mengkonsumsi frame ke-" << j << " [" << Rw.getFrame(j).GetMessage() << "] Mencoba mengirim ACK" << endl; ++consumedByte; Rw.slideWindow(); ++j; } i++; sprintf(res, "%s", (R.GetCompiled()).c_str()); if (sendto(sockfd, res, MaxResponseLength, 0, (struct sockaddr *)&targetAddr, addrLen) == -1) { perror("sendto"); } if ( ( getEOF != 0 ) && ( (getEOF + 1) == consumedByte ) ) { parentExit = 1; } } } Rw.iterateFrames(); printf("Exiting Parent\n"); return NULL; }