void tr_peerIoUnrefImpl( const char * file, int line, tr_peerIo * io ) { assert( tr_isPeerIo( io ) ); dbgmsg( io, "%s:%d is decrementing the IO's refcount from %d to %d", file, line, io->refCount, io->refCount-1 ); if( !--io->refCount ) tr_peerIoFree( io ); }
static void tr_peerIoFree( tr_peerIo * io ) { if( io ) { dbgmsg( io, "in tr_peerIoFree" ); io->canRead = NULL; io->didWrite = NULL; io->gotError = NULL; tr_runInEventThread( io->session, io_dtor, io ); } }
static int readPayloadStream( tr_handshake * handshake, struct evbuffer * inbuf ) { int i; const size_t needlen = HANDSHAKE_SIZE; dbgmsg( handshake, "reading payload stream... have %zu, need %zu", evbuffer_get_length( inbuf ), needlen ); if( evbuffer_get_length( inbuf ) < needlen ) return READ_LATER; /* parse the handshake ... */ i = parseHandshake( handshake, inbuf ); dbgmsg( handshake, "parseHandshake returned %d", i ); if( i != HANDSHAKE_OK ) return tr_handshakeDone( handshake, FALSE ); /* we've completed the BT handshake... pass the work on to peer-msgs */ return tr_handshakeDone( handshake, TRUE ); }
static bool preallocate_file_full (tr_sys_file_t fd, uint64_t length, tr_error ** error) { tr_error * my_error = NULL; if (length == 0) return true; if (tr_sys_file_preallocate (fd, length, 0, &my_error)) return true; dbgmsg ("Preallocating (full, normal) failed (%d): %s", my_error->code, my_error->message); if (!TR_ERROR_IS_ENOSPC (my_error->code)) { uint8_t buf[4096]; bool success = true; memset (buf, 0, sizeof (buf)); tr_error_clear (&my_error); /* fallback: the old-fashioned way */ while (success && length > 0) { const uint64_t thisPass = MIN (length, sizeof (buf)); uint64_t bytes_written; success = tr_sys_file_write (fd, buf, thisPass, &bytes_written, &my_error); length -= bytes_written; } if (success) return true; dbgmsg ("Preallocating (full, fallback) failed (%d): %s", my_error->code, my_error->message); } tr_error_propagate (error, &my_error); return false; }
static void task_finish( struct tr_web_task * task, long response_code ) { dbgmsg( "finished web task %lu; got %ld", task->tag, response_code ); if( task->done_func != NULL ) task->done_func( task->session, response_code, EVBUFFER_DATA( task->response ), EVBUFFER_LENGTH( task->response ), task->done_func_user_data ); task_free( task ); }
static void phaseOne( tr_ptrArray * peerArray, tr_direction dir ) { int i, n; int peerCount = tr_ptrArraySize( peerArray ); struct tr_peerIo ** peers = (struct tr_peerIo**) tr_ptrArrayBase( peerArray ); /* First phase of IO. Tries to distribute bandwidth fairly to keep faster * peers from starving the others. Loop through the peers, giving each a * small chunk of bandwidth. Keep looping until we run out of bandwidth * and/or peers that can use it */ n = peerCount; dbgmsg( "%d peers to go round-robin for %s", n, (dir==TR_UP?"upload":"download") ); i = n ? tr_cryptoWeakRandInt( n ) : 0; /* pick a random starting point */ while( n > 0 ) { /* value of 3000 bytes chosen so that when using uTP we'll send a full-size * frame right away and leave enough buffered data for the next frame to go * out in a timely manner. */ const size_t increment = 3000; const int bytesUsed = tr_peerIoFlush( peers[i], dir, increment ); dbgmsg( "peer #%d of %d used %d bytes in this pass", i, n, bytesUsed ); if( bytesUsed == (int)increment ) ++i; else { /* peer is done writing for now; move it to the end of the list */ tr_peerIo * pio = peers[i]; peers[i] = peers[n-1]; peers[n-1] = pio; --n; } if( i >= n ) i = 0; } }
/*----------------------------------------------------------------------------- * memcpy: * * CAUTION: do not use with overleaping buffers like: char tab[] = "qwertyuiopasdfghjklzxcvbnm"; char* ptr_src = tab; char* ptr_dst = tab + 1; uint32 sz = 5; *-----------------------------------------------------------------------------*/ void *fmf_memcpy( void *dest, const void *src, uint32 count ) { #ifdef LIBSTR_memcpy_linuxkernel_nasm /*----------------------------------------------------------------------------- * 32bit nasm implementation of linux kernel memcpy, it compiles on windows as well *-----------------------------------------------------------------------------*/ #ifdef LIBSTR_DEBUG dbgmsg( "memcpy_linuxkernel_nasm" ); #endif //if( count < 4 ) // only small for now return nasm_memcpy_s( dest, src, count ); //else // return nasm_memcpy_b( dest, src, count ); #elif LIBSTR_memcpy_prefetch /*----------------------------------------------------------------------------- * 32bit nasm implementation of memcpy prefetch *-----------------------------------------------------------------------------*/ #ifdef LIBSTR_DEBUG dbgmsg( "memcpy_prefetch" ); #endif return nasm_memcpy_prefetch( dest, src, count ); #elif LIBSTR_memcpy_linuxkernel_att /*----------------------------------------------------------------------------- * inline AT&T linux kernel memcpy *-----------------------------------------------------------------------------*/ #ifdef LIBSTR_DEBUG dbgmsg( "memcpy_linuxkernel_att" ); #endif int32 d0, d1, d2; if( count < 4 ) { register uint32 dummy; __asm__ __volatile__( "rep; movsb" :"=&D"(dest), "=&S"(src), "=&c"(dummy) :"0" (dest), "1" (src),"2" (count) : "memory"); } else
static void event_disable( struct tr_peerIo * io, short event ) { assert( tr_amInEventThread( io->session ) ); assert( io->session != NULL ); assert( io->session->events != NULL ); assert( event_initialized( &io->event_read ) ); assert( event_initialized( &io->event_write ) ); if( ( event & EV_READ ) && ( io->pendingEvents & EV_READ ) ) { dbgmsg( io, "disabling libevent ready-to-read polling" ); event_del( &io->event_read ); io->pendingEvents &= ~EV_READ; } if( ( event & EV_WRITE ) && ( io->pendingEvents & EV_WRITE ) ) { dbgmsg( io, "disabling libevent ready-to-write polling" ); event_del( &io->event_write ); io->pendingEvents &= ~EV_WRITE; } }
static irqreturn_t gdma1_irq_handler(int irq, void *dev_id) { const unsigned glbsta = readl(DMA_GLOBAL_INT_FLAG); dbgmsg(KERN_DEBUG"DMA Module - %s ISR Start\n", __func__); dbgmsg(KERN_DEBUG"DMA Module - GLBSTA = 0x%x\n", glbsta); if (glbsta & DMA_GLBSTA_IT(G_DMA_1)){ if (dma_ctrl[G_DMA_1].isr_cb) { dma_ctrl[G_DMA_1].isr_cb(dma_ctrl[G_DMA_1].data); } mt65xx_reg_sync_writel(DMA_INT_FLAG_CLR_BIT, DMA_INT_FLAG(DMA_BASE_CH(G_DMA_1))); #if(DMA_DEBUG == 1) glbsta = readl(DMA_GLOBAL_INT_FLAG); printk(KERN_DEBUG"DMA Module - GLBSTA after ack = 0x%x\n", glbsta); #endif } dbgmsg(KERN_DEBUG"DMA Module - %s ISR END\n", __func__); return IRQ_HANDLED; }
static int wait_for_cpu_online(void) { if (!decision_engine_stalled()) return 0; pthread_mutex_lock(&hotplug_mutex); dbgmsg("Waiting for cpu to be online\n"); while (stall_decision) { pthread_cond_wait(&hotplug_condition, &hotplug_mutex); } pthread_mutex_unlock(&hotplug_mutex); return 1; }
static int tr_handshakeDone (tr_handshake * handshake, bool isOK) { bool success; dbgmsg (handshake, "handshakeDone: %s", isOK ? "connected" : "aborting"); tr_peerIoSetIOFuncs (handshake->io, NULL, NULL, NULL, NULL); success = fireDoneFunc (handshake, isOK); tr_handshakeFree (handshake); return success ? READ_LATER : READ_ERR; }
int amba_vtouch_release_abs_mt_sync(struct amba_vtouch_data *data) { if((amba_vtouch_dev==NULL) || (amba_vtouch_dev->input_dev==NULL)){ return -1; } dbgmsg("===> %s, %d,%d\n",__func__, data->finger[0].x, data->finger[0].y); input_report_abs(amba_vtouch_dev->input_dev, ABS_MT_TOUCH_MAJOR, 0); input_mt_sync(amba_vtouch_dev->input_dev); input_sync(amba_vtouch_dev->input_dev); return 0; }
extern Bool CheckNetFile( NETFILE *fp) { Bool ret; if ( fp && fp->fOK ) { ret = TRUE; } else { dbgmsg("bad net file"); ret = FALSE; } return (ret); }
/* This method searches in the local constant pool for a method and returns the index of the method in the MethodLookupTable. */ Method* find_method_name(Class *vmclass, const char *qualifiedName) { unsigned short n, nameIndex; #ifdef DEBUG printf("Link: finding method %s...", qualifiedName); #endif if (vmclass == NULL) { return NULL; } for (n = 0; n < vmclass->MethodsNum; n++) { nameIndex = vmclass->Methods[n].NameIndex - 1; /* Constant Pool index starts with 1, so we must subtract one */ if (strcmp(qualifiedName, ((struct CONSTANT_UTF8_INFO *)vmclass->ConstantPool[nameIndex].Data)->Text) == 0) { dbgmsg("Found method."); return &(vmclass->Methods[n]); } } dbgmsg("Method not found!"); return NULL; }
extern PacketDataType RecvStringData( NETFILE *fp, char *str, size_t size) { PacketDataType type; ENTER_FUNC; type = GL_RecvDataType(fp); switch (type) { case GL_TYPE_INT: dbgmsg("int"); sprintf(str,"%d",GL_RecvInt(fp)); break; case GL_TYPE_CHAR: case GL_TYPE_VARCHAR: case GL_TYPE_DBCODE: case GL_TYPE_TEXT: GL_RecvString(fp, size, str); break; case GL_TYPE_BINARY: case GL_TYPE_BYTE: case GL_TYPE_OBJECT: dbgmsg("LBS"); GL_RecvLBS(fp,LargeBuff); if ( LBS_Size(LargeBuff) > 0 ) { memcpy(str,LBS_Body(LargeBuff),LBS_Size(LargeBuff)); str[LBS_Size(LargeBuff)] = 0; } else { *str = 0; } break; } LEAVE_FUNC; return type; }
static void restore_power_modes() { if(control_sleep_modes == 0) return; dbgmsg("Restoring power modes\n"); if(saved_sapc_idle_en_c0 != -1) set_power_mode(0, "standalone_power_collapse", "idle_enabled", saved_sapc_idle_en_c0 ); if(saved_sapc_idle_en_c1 != -1) set_power_mode(1, "standalone_power_collapse", "idle_enabled", saved_sapc_idle_en_c1 ); if(saved_pc_idle_en_c0 != -1) set_power_mode(0, "power_collapse", "idle_enabled", saved_pc_idle_en_c0); if(saved_pc_idle_en_c1 != -1) set_power_mode(1, "power_collapse", "idle_enabled", saved_pc_idle_en_c1); }
static void task_finish_func( void * vtask ) { struct tr_web_task * task = vtask; dbgmsg( "finished web task %p; got %ld", task, task->code ); if( task->done_func != NULL ) task->done_func( task->session, task->code, evbuffer_pullup( task->response, -1 ), evbuffer_get_length( task->response ), task->done_func_user_data ); task_free( task ); }
static void task_finish_func( void * vtask ) { struct tr_web_task * task = vtask; dbgmsg( "finished web task %p; got %ld", task, task->code ); if( task->done_func != NULL ) task->done_func( task->session, task->code, EVBUFFER_DATA( task->response ), EVBUFFER_LENGTH( task->response ), task->done_func_user_data ); task_free( task ); }
static void sendBitfield(tr_peerMsgs * msgs) { void * bytes; size_t byte_count = 0; // bitfield e seu comprimento struct evbuffer * out = msgs->outMessages; // buffer de saída (...) // Cria o bitfield conforme as partes que possui no momento. bytes = tr_cpCreatePieceBitfield(&msgs->torrent->completion, &byte_count); // <tamanho> = 1 + tamanho do bitfield evbuffer_add_uint32(out, sizeof(uint8_t) + byte_count); evbuffer_add_uint8(out, BT_BITFIELD); // <ID da mensagem> = 5 evbuffer_add(out, bytes, byte_count); // <dados=mapa de bits> dbgmsg(msgs, "sending bitfield... outMessage size is now %zu", evbuffer_get_length(out)); (...) }
// set _current_frame to its n+1'th tail (i.e. pop n+1 frames) // Invariant: result is non-null void _npop_frame(unsigned int n) { struct _ThreadKey *t = tcb(); struct _RuntimeStack *current_frame = t->stack._current_frame; unsigned int i; for(i = n; i <= n; i--) { if(current_frame == NULL) errquit("internal error: empty frame stack\n"); dbgmsg("\nPOPING frame : %p code = %p" , current_frame, current_frame->cleanup); if (current_frame->cleanup != NULL) current_frame->cleanup(current_frame); current_frame = current_frame->next; } t->stack._current_frame = current_frame; }
void tr_peerIoWrite( tr_peerIo * io, const void * bytes, size_t byteCount, tr_bool isPieceData ) { /* FIXME(libevent2): this implementation snould be moved to tr_peerIoWriteBuf. This function should be implemented as evbuffer_new() + evbuffer_add_reference() + a call to tr_peerIoWriteBuf() + evbuffer_free() */ struct tr_datatype * datatype; assert( tr_amInEventThread( io->session ) ); dbgmsg( io, "adding %zu bytes into io->output", byteCount ); datatype = tr_new( struct tr_datatype, 1 ); datatype->isPieceData = isPieceData != 0; datatype->length = byteCount; tr_list_append( &io->outbuf_datatypes, datatype ); switch( io->encryptionMode ) { case PEER_ENCRYPTION_RC4: { /* FIXME(libevent2): use evbuffer_reserve_space() and evbuffer_commit_space() instead of tmp */ void * tmp = tr_sessionGetBuffer( io->session ); const size_t tmplen = SESSION_BUFFER_SIZE; const uint8_t * walk = bytes; evbuffer_expand( io->outbuf, byteCount ); while( byteCount > 0 ) { const size_t thisPass = MIN( byteCount, tmplen ); tr_cryptoEncrypt( io->crypto, thisPass, walk, tmp ); evbuffer_add( io->outbuf, tmp, thisPass ); walk += thisPass; byteCount -= thisPass; } tr_sessionReleaseBuffer( io->session ); break; } case PEER_ENCRYPTION_NONE: evbuffer_add( io->outbuf, bytes, byteCount ); break; default: assert( 0 ); break; } }
static void setsock( curl_socket_t sockfd, int action, struct tr_web * g, struct tr_web_sockinfo * f ) { const int kind = EV_PERSIST | (( action & CURL_POLL_IN ) ? EV_READ : 0 ) | (( action & CURL_POLL_OUT ) ? EV_WRITE : 0 ); dbgmsg( "setsock: fd is %d, curl action is %d, libevent action is %d", sockfd, action, kind ); if( f->evset ) event_del( &f->ev ); event_set( &f->ev, sockfd, kind, event_cb, g ); f->evset = 1; event_add( &f->ev, NULL ); }
static tr_peerIo* tr_peerIoNew( tr_session * session, tr_bandwidth * parent, const tr_address * addr, tr_port port, const uint8_t * torrentHash, tr_bool isIncoming, tr_bool isSeed, int socket ) { tr_peerIo * io; assert( session != NULL ); assert( session->events != NULL ); assert( tr_isBool( isIncoming ) ); assert( tr_isBool( isSeed ) ); assert( tr_amInEventThread( session ) ); if( socket >= 0 ) { tr_netSetTOS( socket, session->peerSocketTOS ); maybeSetCongestionAlgorithm( socket, session->peer_congestion_algorithm ); } io = tr_new0( tr_peerIo, 1 ); io->magicNumber = MAGIC_NUMBER; io->refCount = 1; io->crypto = tr_cryptoNew( torrentHash, isIncoming ); io->session = session; io->addr = *addr; io->isSeed = isSeed; io->port = port; io->socket = socket; io->isIncoming = isIncoming != 0; io->hasFinishedConnecting = FALSE; io->timeCreated = tr_time( ); io->inbuf = evbuffer_new( ); io->outbuf = evbuffer_new( ); tr_bandwidthConstruct( &io->bandwidth, session, parent ); tr_bandwidthSetPeer( &io->bandwidth, io ); dbgmsg( io, "bandwidth is %p; its parent is %p", &io->bandwidth, parent ); event_set( &io->event_read, io->socket, EV_READ, event_read_cb, io ); event_set( &io->event_write, io->socket, EV_WRITE, event_write_cb, io ); return io; }
static int readPadD (tr_handshake * handshake, struct evbuffer * inbuf) { const size_t needlen = handshake->pad_d_len; dbgmsg (handshake, "pad d: need %zu, got %zu", needlen, evbuffer_get_length (inbuf)); if (evbuffer_get_length (inbuf) < needlen) return READ_LATER; tr_peerIoDrain (handshake->io, inbuf, needlen); tr_peerIoSetEncryption (handshake->io, handshake->crypto_select); setState (handshake, AWAITING_HANDSHAKE); return READ_NOW; }
static int readPadC( tr_handshake * handshake, struct evbuffer * inbuf ) { uint16_t ia_len; const size_t needlen = handshake->pad_c_len + sizeof( uint16_t ); if( evbuffer_get_length( inbuf ) < needlen ) return READ_LATER; evbuffer_drain( inbuf, handshake->pad_c_len ); tr_peerIoReadUint16( handshake->io, inbuf, &ia_len ); dbgmsg( handshake, "ia_len is %d", (int)ia_len ); handshake->ia_len = ia_len; setState( handshake, AWAITING_IA ); return READ_NOW; }
static void *mpdecision_server(void *data) { int rc, len; int online; int conn_socket = 0; char msgbuf[MAX_BUF] = {0}; if (comsoc < 0) return NULL; for (;;) { len = sizeof(struct sockaddr_un); conn_socket = accept(comsoc, (struct sockaddr *) &addr, &len); if (conn_socket == -1) { msg("%s: accept failed", __func__); continue; } memset(msgbuf, 0, MAX_BUF); rc = recv(conn_socket, msgbuf, MAX_BUF, 0); if (rc <= 0) { msg("%s: recv failed", __func__); goto close_conn; } dbgmsg("%s: received msg %s", __func__, msgbuf); if (rc >= MAX_BUF) msgbuf[MAX_BUF - 1] = '\0'; else msgbuf[rc] = '\0'; rc = sscanf(msgbuf, "hotplug %d", &online); if (rc != 1 || !(online == 0 || online == 1)) { msg("%s: msg format unexpected", __func__); } else { thermal_force_coredown(online); } close_conn: close(conn_socket); } return NULL; }
int tr_peerIoFlush( tr_peerIo * io, tr_direction dir, size_t limit ) { int bytesUsed = 0; assert( tr_isPeerIo( io ) ); assert( tr_isDirection( dir ) ); if( io->hasFinishedConnecting ) { if( dir == TR_DOWN ) bytesUsed = tr_peerIoTryRead( io, limit ); else bytesUsed = tr_peerIoTryWrite( io, limit ); } dbgmsg( io, "flushing peer-io, hasFinishedConnecting %d, direction %d, limit %zu, bytesUsed %d", (int)io->hasFinishedConnecting, (int)dir, limit, bytesUsed ); return bytesUsed; }
static void tr_multi_perform( tr_web * g, int fd, int curl_what ) { CURLMcode m; dbgmsg( "check_run_count: %d taskCount", g->taskCount ); /* invoke libcurl's processing */ do m = curl_multi_socket_action( g->multi, fd, curl_what, &g->taskCount ); while( m == CURLM_CALL_MULTI_SOCKET ); remove_finished_tasks( g ); if( g->closing && !g->taskCount ) web_free( g ); else restart_timer( g ); }
static void GL_RecvLBS( NETFILE *fp, LargeByteString *lbs) { size_t size; ENTER_FUNC; size = GL_RecvLength(fp); LBS_ReserveSize(lbs,size,FALSE); if ( size > 0 ) { Recv(fp,LBS_Body(lbs),size); if ( !CheckNetFile(fp) ) { GL_Error(); } } else { dbgmsg("Recv LBS 0 size."); } LEAVE_FUNC; }
static void DumpDirectory(void) { int i; ENTER_FUNC; InitDirectory(); SetUpDirectory(Directory,NULL,NULL,NULL,P_ALL); printf("name = [%s]\n",ThisEnv->name); printf("mlevel = %d\n" ,ThisEnv->mlevel); printf("cLD = %d\n" ,(int)ThisEnv->cLD); printf("cBD = %d\n" ,(int)ThisEnv->cBD); printf("cDBD = %d\n" ,(int)ThisEnv->cDBD); #if 0 printf("LINK ---------\n"); DumpRecord(ThisEnv->linkrec); #endif if ( fLD ) { printf("LD ----------\n"); for ( i = 0 ; i < ThisEnv->cLD ; i ++ ) { DumpLD(ThisEnv->ld[i]); } } if ( fBD ) { printf("BD ----------\n"); for ( i = 0 ; i < ThisEnv->cBD ; i ++ ) { DumpBD(ThisEnv->bd[i]); } } if ( fDBD ) { printf("DBD ----------\n"); for ( i = 0 ; i < ThisEnv->cDBD ; i ++ ) { DumpDBD(ThisEnv->db[i]); } } if ( fDBG ) { printf("DBG ---------\n"); g_hash_table_foreach(ThisEnv->DBG_Table,(GHFunc)DumpDBG,NULL); } dbgmsg("<DumpDirectory"); }