#include <NetMgr.h>
Public Member Functions | |
NetMgr (bool serverInstance=false) | |
NetMgr tem o parametro serverInstance por default igual a false. | |
~NetMgr () | |
int | Start (int port, int maxdiskl, int maxpktl, unsigned int MaxCreditsClients=0, unsigned int MaxNetworkCredits=0, unsigned int NetworkRate=0) |
int | Stop () |
void | getmyaddrport (int *ipaddr, int *port, int server=0) |
void | getalladdrport (int **ipaddr, int **port) |
int | getipaddr () |
void | SetCmdProc (cmdcallback_t cmdproc, void *cmdparm) |
Este metodo nao esta sendo usado em lugar nenhum do codigo. | |
void | SendCmd (int ipadr, int port, int reqid, char *cmdp, int cmdl, callback_t callback, void *callbackparm) |
void | SendResult (int ipadr, int port, int reqid, int result) |
void | SendBlock (int ipadr, int port, int reqid, char *bufadr, int buflen, callback_t callback, void *callbackparm, int StreamTraffic, unsigned int VideoRate=0) |
int | ExpectBlock (char *buf, int len, callback_t callback, void *callbackparm, int sendack=1) |
int | CancelExpect (int reqid, int result) |
void | TellId (int ipadr, int port, int reqid, int tellip, int tellport, int tellreqid, callback_t callback, void *callbackparm) |
void | GetBlock (int ipadr, int port, int reqid, char *bufadr, int buflen, callback_t callback, void *callbackparm) |
int | ExpectTellId (char *buf, int len, callback_t callback, void *callbackparm) |
bool | SetMulticastSocket (unsigned short multicastport, char *multicast_addr, void *callback=0, BufferStream *buffer_stream=0, int enable_join=1) |
void | LeaveGroup (unsigned short multicastport) |
void | LeaveAllGroups (void) |
int | FreeBlock (unsigned int block_id, RioStreamType traffic) |
int | FreePendentBlocks (bool useCache, int nBuffers) |
bool | thereAreFragments (RioBlock block) |
void | Getmyaddr (int *my_address, int *my_port) |
int | CreateKeepaliveThread (void) |
CreateKeepaliveThread funcao para criar a thread usada para enviar periodicamente mensagens Fake aos servidores para garantir que os mapeamentos nao serao expirados por timeout. | |
bool | IsBehindNAT () |
IsBehindNAT esta funcao retorna true se o cliente estiver atras de um NAT, caso a funcao RequestMapping tenha sido chamada pelo cliente para obter o mapeamento, e false caso o cliente nao esteja atras do NAT ou se a funcao RequestMapping nao tenha sido chamada. | |
void | RequestMultipleMappings (struct sockaddr_in *addr, int size) |
RequestMultipleMappings faz requisicao a outros objetos NetMgr, pedindo o mapeamento, isto e, o endereco IP e a porta visivel por este objeto. | |
void | RequestMapping (int ipaddr, int port) |
RequestMapping faz uma requisicao a um outro objeto NetMgr, pedindo o mapeamento, isto e, o endereco IP e a porta visivel por este objeto. | |
void | setLogRotation (CLogRotation *LogRotation) |
Funcao para definir o objeto (do tipo CLogRotation) a ser usado para armazenas as estatisticas de envio de pacotes. | |
int | ExpectCmd (callback_t callback, void *callbackparm, cmdcallback_t cmdcallback) |
Nova chamada para usar a funcao ExpectCmd da RioNeti. | |
void | SendRst (int ipaddr, int port, int reqid, int result) |
Esta funcao, que antes era private na RioNeti, agora passou a ser public para permitir que enviemos um erro para cancelar um pedido pendende. | |
Static Public Member Functions | |
static void | dumppkt (const char *, char *, int) |
Static Private Member Functions | |
static void | mycmdproc (void *cmdparm, char *cmdp, int cmdl) |
static void | getblockcbx (void *parm, int result) |
static void | getblockcb1 (void *parm, int result) |
static void | getblockcb2 (void *parm, int result) |
static void | sendresultcb (void *parm, int result) |
static void | expecttellcom (void *parm) |
static void | expecttellcmplt (void *parm, int result) |
static void | expecttellsend (void *parm, int result) |
static void | expecttellcmd (void *parm, char *pktp, int pktl) |
static void | CallbackRequestMapping (void *param, int result) |
CallbackRequestMapping: funcao callback usada para liberar o semaforo quando a operacao de pedido de mapeamento ao servidor (iniciada pela chamada a funcao RequestMapping da classe NetMgr) estiver finalizada. | |
Private Attributes | |
RioNeti * | d_neti |
cmdcallback_t | d_cmdproc |
void * | d_cmdparm |
int | d_myip |
int | d_myport |
int | d_seq |
bool | serverInstance |
CSemaphore * | m_semalidmap |
pthread_mutex_t | d_seqlock |
Definition at line 49 of file NetMgr.h.
NetMgr::NetMgr | ( | bool | serverInstance = false |
) |
NetMgr tem o parametro serverInstance por default igual a false.
Indica se esta instancia da NetMgr foi criada no servidor (true) ou nao, se foi criada no cliente (false).
Definition at line 61 of file NetMgr.cpp.
00062 { 00063 this->serverInstance = serverInstance; 00064 d_neti = NULL; 00065 d_cmdproc = 0; 00066 d_myip = 0; 00067 d_myport = 0; 00068 d_seq = 0; 00069 d_cmdparm = NULL; 00070 00071 #ifdef WINDOWS 00072 // Windows implementation 00073 d_seqlock = CreateMutex(NULL, FALSE, NULL); 00074 #else 00075 // Linux implementation 00076 pthread_mutex_init(&d_seqlock, NULL); 00077 #endif 00078 00079 // Inicializacos das novas variveis usadas pela implementacao que permite 00080 // clientes atras de NAT. 00081 m_semalidmap = new CSemaphore( 0, 1 ); 00082 }
NetMgr::~NetMgr | ( | ) |
Definition at line 85 of file NetMgr.cpp.
00086 { 00087 if( d_neti ) 00088 { 00089 d_neti->Stop(); 00090 delete d_neti; 00091 d_neti = 0; 00092 00093 #ifdef WINDOWS 00094 // Windows implementation 00095 CloseHandle(d_seqlock); 00096 #else 00097 // Linux implementation 00098 pthread_mutex_destroy(&d_seqlock); 00099 #endif 00100 } 00101 00102 // Remocao do semaforo usado pela implementacao que permite clientes atras 00103 // de NAT. 00104 delete m_semalidmap; 00105 }
void NetMgr::CallbackRequestMapping | ( | void * | param, | |
int | result | |||
) | [static, private] |
CallbackRequestMapping: funcao callback usada para liberar o semaforo quando a operacao de pedido de mapeamento ao servidor (iniciada pela chamada a funcao RequestMapping da classe NetMgr) estiver finalizada.
Ela e chamada quando a mensagem de requisicao e corretamente enviada e quando o ACK desta mensagem, com o mapeamento, chega com sucesso ao cliente.
param | ponteiro para a instancia do objeto da classe NetMgr bloqueado na funcao RequestMapping. | |
result | nao e usado pela implementacao da callback, mas e necessario defini-lo pois todas as callbacks devem ter a mesma interface. |
Definition at line 861 of file NetMgr.cpp.
00862 { 00863 NetMgr *PNetMgr; 00864 #ifdef RIO_DEBUG1 00865 RioErr << "NetMgr::CallbackRequestMapping chamada. Result = 0x" << hex 00866 << ( unsigned int ) result << dec << endl; 00867 #endif 00868 PNetMgr = (NetMgr *) param; 00869 // Desbloqueia o processo cliente, que ficou bloqueado na funcao 00870 // RequestMapping esperando pelo recebimento do mapeamento. 00871 PNetMgr->m_semalidmap->V(); 00872 }
int NetMgr::CancelExpect | ( | int | reqid, | |
int | result | |||
) |
Definition at line 305 of file NetMgr.cpp.
00306 { 00307 return d_neti->CancelExpect(reqid, result); 00308 }
int NetMgr::CreateKeepaliveThread | ( | void | ) |
CreateKeepaliveThread funcao para criar a thread usada para enviar periodicamente mensagens Fake aos servidores para garantir que os mapeamentos nao serao expirados por timeout.
ServerAddress | ponteiro para um vetor com os enderecos dos servidores. Cada endereco e composto pelo IP do servidor e pela porta UDP usada por ele. | |
ServerAddressSize | tamanho do vetor com os enderecos dos servidores. |
Definition at line 814 of file NetMgr.cpp.
00816 { 00817 return( d_neti->CreateKeepaliveThread( ) ); 00818 }
void NetMgr::dumppkt | ( | const char * | label, | |
char * | data, | |||
int | datal | |||
) | [static] |
Definition at line 745 of file NetMgr.cpp.
00746 { 00747 int off; 00748 int i; 00749 char *s; 00750 char line[100]; 00751 00752 RioErr << label; 00753 00754 off = 0; 00755 do 00756 { 00757 s = line; 00758 s += sprintf(s,"%4.4x ", (unsigned) off); 00759 00760 for(i = 0; i < 16 && i < datal; i++, data++) 00761 { 00762 s += sprintf(s, "%2.2x", (unsigned)(*data & 0xff)); 00763 if((i & 3) == 3) 00764 { 00765 *s++ = ' '; 00766 } 00767 } 00768 00769 *s++ = '\n'; 00770 *s++ = '\0'; 00771 00772 if(off > 0x20 && off < 0x5a0) 00773 ; 00774 else 00775 RioErr << line; 00776 00777 datal -= 16; 00778 off += 16; 00779 } while(datal > 0); 00780 00781 RioErr << endl; 00782 00783 }
int NetMgr::ExpectBlock | ( | char * | buf, | |
int | len, | |||
callback_t | callback, | |||
void * | callbackparm, | |||
int | sendack = 1 | |||
) |
Definition at line 280 of file NetMgr.cpp.
00282 { 00283 #ifdef RIO_DEBUG2 00284 RioErr << "[NetMgr] ExpectBlock chamando ExpectData." << endl; 00285 #endif 00286 00287 return d_neti->ExpectData( bufadr, buflen, callback, callbackparm, 00288 UNICASTTRAFFIC, sendack ); 00289 }
int NetMgr::ExpectCmd | ( | callback_t | callback, | |
void * | callbackparm, | |||
cmdcallback_t | cmdcallback | |||
) |
Nova chamada para usar a funcao ExpectCmd da RioNeti.
callback | callback a ser chamada quando o objeto NetBuf criado for removido. | |
callbackparm | parametro a ser passado a callback. | |
cmdcallback | callback a ser chamada quando recebermos a resposta com o tamanho do arquivo de busca e o identificador deste arquivo. |
Definition at line 883 of file NetMgr.cpp.
void NetMgr::expecttellcmd | ( | void * | parm, | |
char * | pktp, | |||
int | pktl | |||
) | [static, private] |
Definition at line 564 of file NetMgr.cpp.
00565 { 00566 xtwork *wp = (xtwork *) parm; 00567 int i; 00568 u32 data[5], *dp; 00569 00570 dp = (u32 *) pktp; 00571 for(i = 0; i < 5; i++) 00572 { 00573 data[i] = *dp++; 00574 } 00575 00576 // most byte order is already ok, fix up some 00577 data[0] = ntohl(data[0]); // command 00578 data[2] = htons( (short) (ntohl(data[2]))); 00579 data[4] = ntohl(data[4]); // seq id 00580 00581 if(data[0] != (unsigned) RioPktC::CMD_TELLID) 00582 { 00583 return; 00584 } 00585 00586 // check for duplicate tellid here.. / add to duplicate table.. 00587 for(i = 0; i < wp->dupct; i++) 00588 { 00589 if( data[1] == wp->duptab[i].ip && 00590 data[2] == wp->duptab[i].port && 00591 data[3] == wp->duptab[i].reqid && 00592 data[4] == wp->duptab[i].seq 00593 ) 00594 { 00595 #ifdef RIO_DEBUG2 00596 RioErr << " -- duplicate --" << endl; 00597 #endif 00598 return; // duplicate cmd 00599 } 00600 } 00601 00602 if(wp->dupct < xtwork::DUPTABN-1) 00603 { 00604 wp->dupix = ++wp->dupct; 00605 } 00606 else 00607 { 00608 ++wp->dupix; 00609 if(wp->dupix >= xtwork::DUPTABN-1) 00610 { 00611 wp->dupix = 0; // wrap spot to use 00612 } 00613 } 00614 00615 i = wp->dupix; 00616 wp->duptab[i].ip = data[1]; 00617 wp->duptab[i].port = data[2]; 00618 wp->duptab[i].reqid = data[3]; 00619 wp->duptab[i].seq = data[4]; 00620 00621 wp->pendingsends++; 00622 00623 #ifdef RIO_DEBUG2 00624 in_addr dest; 00625 dest.s_addr = wp->duptab[ i ].ip; 00626 RioErr << "NetMgr::expecttellcmd recebido as informacoes do bloco " 00627 << "ao NetBuf com o identificador wp->myreqid = " << wp->myreqid 00628 << ", associado a posicao " << i << " de wp->duptab, com as " 00629 << "seguintes informacoes: ip = " << inet_ntoa( dest ) 00630 << ", porta = " << ntohs( wp->duptab[ i ].port ) << ", reqid = " 00631 << wp->duptab[ i ].reqid << " e seq = " << wp->duptab[ i ].seq 00632 << ". wp->pendingsends = " << wp->pendingsends << endl; 00633 00634 RioErr << "[NetMgr] expecttellcmd - chamando a SendData" << endl; 00635 #endif 00636 00637 wp->mgr->d_neti->SendData( data[1], data[2], data[3], wp->bufp, wp->bufl, 00638 &expecttellsend, (void *) wp, 1, 0, 00639 &wp->duptab[i].sendreqid ); 00640 }
void NetMgr::expecttellcmplt | ( | void * | parm, | |
int | result | |||
) | [static, private] |
Definition at line 665 of file NetMgr.cpp.
00666 { 00667 xtwork *wp = (xtwork *) parm; 00668 00669 wp->cmplt = 1; 00670 00671 wp->result = result; 00672 00673 // Se ocorrer algum erro, cancelamos todos os envios de blocos pendentes. 00674 if( result != S_OK ) 00675 { 00676 #ifdef RIO_DEBUG2 00677 RioErr << "NetMgr::expecttellcmplt a copia do bloco terminou com o " 00678 << "erro 0x" << hex << ( unsigned int ) result << dec << " (" 00679 << GetErrorDescription( result ) << "). Abortando todas as " 00680 << "copias pendentes para o NetBuf com a identificacao " 00681 << "wp->myreqid = " << wp->myreqid << endl; 00682 RioErr << "NetMgr::expecttellcmplt wp->pendingsends = " 00683 << wp->pendingsends << ", wp->dupix = " << wp->dupix 00684 << " e xtwork::DUPTABN = " << xtwork::DUPTABN << endl; 00685 #endif 00686 // Remove todas as entradas. Isso esta correto (wp->dupix -> ultima 00687 // entrada usada, mas pode voltar para 0 caso seja maior ou igual a 00688 // xtwork::DUPTABN). 00689 for( int i = 0; i < xtwork::DUPTABN; i++ ) 00690 { 00691 if( wp->duptab[ i ].ip != 0 ) 00692 { 00693 00694 #ifdef RIO_DEBUG2 00695 in_addr sip; 00696 sip.s_addr = wp->duptab[ i ].ip; 00697 RioErr << "NetMgr::expecttellcmplt cancelando o envio do bloco " 00698 << "na posicao " << i << " de wp->duptab, com as " 00699 << "seguintes informacoes: ip = " << inet_ntoa( sip ) 00700 << ", porta = " << ntohs( wp->duptab[ i ].port ) 00701 << ", reqid = " << wp->duptab[ i ].reqid << ", seq = " 00702 << wp->duptab[ i ].seq << " e sendreqid = " 00703 << wp->duptab[ i ].sendreqid << endl; 00704 #endif 00705 00706 if( !wp->mgr->d_neti->CancelCopyBlock( wp->duptab[ i ].sendreqid, 00707 result ) ) 00708 { 00709 #ifdef RIO_DEBUG2 00710 RioErr << "NetMgr::expecttellcmplt erro ao cancelar o envio " 00711 << "do bloco com a seqreqid " 00712 << wp->duptab[ i ].sendreqid << endl; 00713 #endif 00714 } 00715 } 00716 } 00717 } 00718 00719 expecttellcom((void *) wp); 00720 }
void NetMgr::expecttellcom | ( | void * | parm | ) | [static, private] |
Definition at line 644 of file NetMgr.cpp.
00645 { 00646 xtwork *wp = (xtwork *) parm; 00647 00648 #ifdef RIO_DEBUG2 00649 RioErr << "[NetMgr] expecttellcom - Chamando a MulticastCallBack da " 00650 << "RioMMVideo" << endl; 00651 #endif 00652 00653 if(wp->cmplt && wp->pendingsends == 0) 00654 { 00655 #ifdef RIO_DEBUG2 00656 RioErr << "[NetMgr] expecttellcom - Chamando a callback" << endl; 00657 #endif 00658 (*wp->callback)(wp->callbackparm, wp->result); 00659 delete wp; 00660 } 00661 }
int NetMgr::ExpectTellId | ( | char * | buf, | |
int | len, | |||
callback_t | callback, | |||
void * | callbackparm | |||
) |
Definition at line 533 of file NetMgr.cpp.
00535 { 00536 xtwork *wp = new xtwork; 00537 00538 wp->mgr = this; 00539 wp->callback = callback; 00540 wp->callbackparm = callbackparm; 00541 wp->bufp = bufadr; 00542 wp->bufl = buflen; 00543 wp->result = 0; 00544 wp->dupix = 0; 00545 wp->dupct = 0; 00546 wp->pendingsends = 0; 00547 wp->cmplt = 0; 00548 // Inicializa o vetor com as reqids. 00549 for( int i = 0; i < xtwork::DUPTABN; i++ ) 00550 { 00551 wp->duptab[ i ].ip = 0; 00552 wp->duptab[ i ].port = 0; 00553 wp->duptab[ i ].reqid = 0; 00554 wp->duptab[ i ].seq = 0; 00555 } 00556 wp->myreqid = d_neti->ExpectCmd( &expecttellcmplt, 00557 (void *) wp, &expecttellcmd); 00558 00559 return wp->myreqid; 00560 }
void NetMgr::expecttellsend | ( | void * | parm, | |
int | result | |||
) | [static, private] |
Definition at line 728 of file NetMgr.cpp.
00729 { 00730 xtwork *wp = (xtwork *) parm; 00731 00732 #ifdef RIO_DEBUG2 00733 RioErr << "NetMgr::expecttellsend recebido a confirmacao do envio de um " 00734 << "bloco: wp->pendingsends = " << wp->pendingsends 00735 << ", wp->cmplt = " << wp->cmplt << ", result = 0x" 00736 << hex << result << dec << " (" << GetErrorDescription( result ) 00737 << ")" << endl; 00738 #endif 00739 00740 wp->pendingsends--; 00741 expecttellcom((void *) wp); 00742 }
int NetMgr::FreeBlock | ( | unsigned int | block_id, | |
RioStreamType | traffic | |||
) |
Definition at line 786 of file NetMgr.cpp.
int NetMgr::FreePendentBlocks | ( | bool | useCache, | |
int | nBuffers | |||
) |
Definition at line 791 of file NetMgr.cpp.
00792 { 00793 return( d_neti->FreePendentBlocks( useCache, nbuffers ) ); 00794 }
void NetMgr::getalladdrport | ( | int ** | ipaddr, | |
int ** | port | |||
) |
Definition at line 199 of file NetMgr.cpp.
00200 { 00201 d_neti->getalladdrport( ipaddr, port ); 00202 }
void NetMgr::GetBlock | ( | int | ipadr, | |
int | port, | |||
int | reqid, | |||
char * | bufadr, | |||
int | buflen, | |||
callback_t | callback, | |||
void * | callbackparm | |||
) |
Definition at line 388 of file NetMgr.cpp.
00390 { 00391 gbwork *wp = new gbwork; 00392 00393 wp->tellcmplt = false; 00394 wp->expectcmplt = false; 00395 wp->result = 0; 00396 wp->mgr = this; 00397 wp->callback = callback; 00398 wp->callbackparm = callbackparm; 00399 wp->myreqid = ExpectBlock( buf, len, &getblockcb1, wp, 1 ); 00400 00401 TellId( ipadr, port, reqid, d_myip, d_myport, wp->myreqid, 00402 &getblockcb2, wp ); 00403 }
void NetMgr::getblockcb1 | ( | void * | parm, | |
int | result | |||
) | [static, private] |
Definition at line 436 of file NetMgr.cpp.
00437 { 00438 #ifdef RIO_DEBUG1 00439 RioErr << "[NetMgr] getblockcb1 - Start" << endl; 00440 #endif 00441 gbwork *wp = (gbwork *) parm; 00442 00443 wp->expectcmplt = true; 00444 00445 getblockcbx( wp, result ); 00446 #ifdef RIO_DEBUG1 00447 RioErr << "[NetMgr] getblockcb1 - Finish" << endl; 00448 #endif 00449 }
void NetMgr::getblockcb2 | ( | void * | parm, | |
int | result | |||
) | [static, private] |
Definition at line 453 of file NetMgr.cpp.
00454 { 00455 #ifdef RIO_DEBUG1 00456 RioErr << "[NetMgr] getblockcb2 - Start" << endl; 00457 #endif 00458 gbwork *wp = (gbwork *) parm; 00459 00460 wp->tellcmplt = true; 00461 00462 if(result) 00463 { // some tellid error 00464 #ifdef RIO_DEBUG1 00465 RioErr << "[NetMgr] getblockcb1 - Error" << endl; 00466 #endif 00467 wp->mgr->CancelExpect(wp->myreqid, ERROR_NETMGR+0xf0); 00468 } 00469 00470 getblockcbx(wp, result); 00471 #ifdef RIO_DEBUG1 00472 RioErr << "[NetMgr] getblockcb2 - Finish" << endl; 00473 #endif 00474 }
void NetMgr::getblockcbx | ( | void * | parm, | |
int | result | |||
) | [static, private] |
Definition at line 407 of file NetMgr.cpp.
00408 { 00409 #ifdef RIO_DEBUG1 00410 RioErr << "[NetMgr] getblockcbx - Start" << endl; 00411 #endif 00412 gbwork *wp = (gbwork *) parm; 00413 00414 if(!wp->result) 00415 wp->result = result; 00416 00417 if(wp->tellcmplt && wp->expectcmplt) 00418 { 00419 #ifdef RIO_DEBUG2 00420 RioErr << "[NetMgr] getblockcbx - Chamando a MulticastCallBack da " 00421 << "RioMMVideo" << endl; 00422 #endif 00423 00424 (*wp->callback)(wp->callbackparm, wp->result); 00425 delete wp; 00426 } 00427 #ifdef RIO_DEBUG1 00428 RioErr << "[NetMgr] getblockcbx - Finish" << endl; 00429 #endif 00430 }
int NetMgr::getipaddr | ( | ) |
Definition at line 208 of file NetMgr.cpp.
void NetMgr::Getmyaddr | ( | int * | my_address, | |
int * | my_port | |||
) |
Definition at line 158 of file NetMgr.cpp.
void NetMgr::getmyaddrport | ( | int * | ipaddr, | |
int * | port, | |||
int | server = 0 | |||
) |
Definition at line 192 of file NetMgr.cpp.
00193 { 00194 d_neti->getmyaddrport( ipaddr, port, server ); 00195 }
bool NetMgr::IsBehindNAT | ( | ) |
IsBehindNAT esta funcao retorna true se o cliente estiver atras de um NAT, caso a funcao RequestMapping tenha sido chamada pelo cliente para obter o mapeamento, e false caso o cliente nao esteja atras do NAT ou se a funcao RequestMapping nao tenha sido chamada.
Definition at line 822 of file NetMgr.cpp.
00823 { 00824 return( d_neti->IsBehindNAT() ); 00825 }
void NetMgr::LeaveAllGroups | ( | void | ) |
Definition at line 185 of file NetMgr.cpp.
00186 { 00187 d_neti->LeaveAllGroups(); 00188 }
void NetMgr::LeaveGroup | ( | unsigned short | multicastport | ) |
Definition at line 179 of file NetMgr.cpp.
00180 { 00181 d_neti->LeaveGroup( multicastport ); 00182 }
void NetMgr::mycmdproc | ( | void * | cmdparm, | |
char * | cmdp, | |||
int | cmdl | |||
) | [static, private] |
void NetMgr::RequestMapping | ( | int | ipaddr, | |
int | port | |||
) |
RequestMapping faz uma requisicao a um outro objeto NetMgr, pedindo o mapeamento, isto e, o endereco IP e a porta visivel por este objeto.
O outro objeto esta executando em uma maquina com endereco IP e porta dados pelos parametros da funcao. Esta funcao deve ser chamada apos a inicializacao do socket, isto e, somente apos a funcao Start ter sido executada. A funcao de callback passada como parametro e chamada apos um mapeamento ter sido recebido.
Definition at line 829 of file NetMgr.cpp.
00830 { 00831 d_neti->RequestMapping( ipaddr, port, 0, &CallbackRequestMapping, this ); 00832 // Espera ate que o mapeamento seja retornado pelo servidor. 00833 m_semalidmap->P(); 00834 d_neti->getmyaddrport( &d_myip, &d_myport ); 00835 }
void NetMgr::RequestMultipleMappings | ( | struct sockaddr_in * | addr, | |
int | size | |||
) |
RequestMultipleMappings faz requisicao a outros objetos NetMgr, pedindo o mapeamento, isto e, o endereco IP e a porta visivel por este objeto.
Os outros objetos estao executando em maquinas com endereco IP e porta dados no primeiro parametro da funcao. Esta funcao deve ser chamada apos a inicializacao do socket, isto e, somente apos a funcao Start ter sido executada. A funcao de callback passada como parametro e chamada apos um mapeamento ter sido recebido.
addr | vetor de enderecos IP e portas dos objetos NetMgr. | |
size | quantidades de objetos NetMgr. |
Definition at line 839 of file NetMgr.cpp.
00840 { 00841 int ipaddr, port; 00842 d_neti->allocMappingVectors( size ); 00843 for( int i = 0; i < size; i++ ) 00844 { 00845 ipaddr = addr[ i ].sin_addr.s_addr; 00846 port = addr[ i ].sin_port; 00847 d_neti->RequestMapping( ipaddr, port, i, &CallbackRequestMapping, 00848 this ); 00849 // Espera ate que o mapeamento seja retornado pelo servidor. 00850 m_semalidmap->P(); 00851 // Inicializa d_myip e d_myport com o endereco do servidor (que esta na 00852 // posicao 0). 00853 if( i == 0 ) 00854 d_neti->getmyaddrport( &d_myip, &d_myport ); 00855 } 00856 }
void NetMgr::SendBlock | ( | int | ipadr, | |
int | port, | |||
int | reqid, | |||
char * | bufadr, | |||
int | buflen, | |||
callback_t | callback, | |||
void * | callbackparm, | |||
int | StreamTraffic, | |||
unsigned int | VideoRate = 0 | |||
) |
Definition at line 257 of file NetMgr.cpp.
00260 { 00261 #ifdef RIO_DEBUG1 00262 RioErr << "[NetMgr] SendBlock Start" << endl; 00263 #endif 00264 d_neti->SendData( ip, port, reqid, bufadr, buflen, callback, callbackparm, 00265 StreamTraffic, VideoRate ); 00266 #ifdef RIO_DEBUG1 00267 RioErr << "[NetMgr] SendBlock Finish" << endl; 00268 #endif 00269 }
void NetMgr::SendCmd | ( | int | ipadr, | |
int | port, | |||
int | reqid, | |||
char * | cmdp, | |||
int | cmdl, | |||
callback_t | callback, | |||
void * | callbackparm | |||
) |
Definition at line 239 of file NetMgr.cpp.
void NetMgr::SendResult | ( | int | ipadr, | |
int | port, | |||
int | reqid, | |||
int | result | |||
) |
Definition at line 320 of file NetMgr.cpp.
00321 { 00322 d_neti->SendResult( ipadr, port, reqid, result, 00323 &sendresultcb, (void *)this); 00324 }
void NetMgr::sendresultcb | ( | void * | parm, | |
int | result | |||
) | [static, private] |
Definition at line 327 of file NetMgr.cpp.
void NetMgr::SendRst | ( | int | ipaddr, | |
int | port, | |||
int | reqid, | |||
int | result | |||
) |
Esta funcao, que antes era private na RioNeti, agora passou a ser public para permitir que enviemos um erro para cancelar um pedido pendende.
Isso ocorrera quando, ao cliente solicitar uma busca nos logs do servidor, pedir ou um bloco que um arquivo com os resultados de uma busca cuja identificacao nao existe, ou se pedir um bloco invalido deste arquivo. A funcao foi criada na NetMgr para permitir acessarmos a funcao correspondente da RioNeti.
ipaddr | endereco IP para onde deveremos enviar o codigo de erro. | |
port | porta para onde deveremos enviar o codigo de erro. | |
reqid | identificacao do NetBuf que desejamos enviar o erro. | |
result | codigo de erro a ser enviado. |
Definition at line 890 of file NetMgr.cpp.
void NetMgr::SetCmdProc | ( | cmdcallback_t | cmdproc, | |
void * | cmdparm | |||
) |
Este metodo nao esta sendo usado em lugar nenhum do codigo.
Definition at line 219 of file NetMgr.cpp.
00220 { 00221 d_cmdproc = cmdproc; 00222 d_cmdparm = cmdparm; 00223 00224 d_neti->SetCmdProc(mycmdproc, (void *)this); 00225 }
void NetMgr::setLogRotation | ( | CLogRotation * | LogRotation | ) |
Funcao para definir o objeto (do tipo CLogRotation) a ser usado para armazenas as estatisticas de envio de pacotes.
LogRotation | ponteiro para um objeto do tipo CLogRotation. |
Definition at line 876 of file NetMgr.cpp.
00877 { 00878 d_neti->setLogRotation( LogRotation ); 00879 }
bool NetMgr::SetMulticastSocket | ( | unsigned short | multicastport, | |
char * | multicast_addr, | |||
void * | callback = 0 , |
|||
BufferStream * | buffer_stream = 0 , |
|||
int | enable_join = 1 | |||
) |
Definition at line 165 of file NetMgr.cpp.
00170 { 00171 return d_neti->SetMulticastSocket( multicastport, 00172 multicast_addr, 00173 callback, 00174 buffer_stream, 00175 enable_join ); 00176 }
int NetMgr::Start | ( | int | port, | |
int | maxdiskl, | |||
int | maxpktl, | |||
unsigned int | MaxCreditsClients = 0 , |
|||
unsigned int | MaxNetworkCredits = 0 , |
|||
unsigned int | NetworkRate = 0 | |||
) |
Definition at line 132 of file NetMgr.cpp.
00136 { 00137 int rc; 00138 00139 d_neti = new RioNeti( serverInstance ); 00140 // Mudanca para passar, ao objeto RioNeti, os novos parametros 00141 // RioNetiLogPath, MaxClientsCredits, MaxNetworkCredits e NetworkRate. 00142 #ifdef RIO_DEBUG_FILE 00143 rc = d_neti->Start( port, maxdiskl, maxpktl, RioNetiLogPath, 00144 MaxClientsCredits, MaxNetworkCredits, NetworkRate ); 00145 #else 00146 rc = d_neti->Start( port, maxdiskl, maxpktl, MaxClientsCredits, 00147 MaxNetworkCredits, NetworkRate ); 00148 #endif 00149 00150 if( rc ) 00151 return rc; 00152 00153 d_neti->getmyaddrport( &d_myip, &d_myport ); 00154 return rc; 00155 }
int NetMgr::Stop | ( | void | ) |
Definition at line 214 of file NetMgr.cpp.
void NetMgr::TellId | ( | int | ipadr, | |
int | port, | |||
int | reqid, | |||
int | tellip, | |||
int | tellport, | |||
int | tellreqid, | |||
callback_t | callback, | |||
void * | callbackparm | |||
) |
Definition at line 335 of file NetMgr.cpp.
00338 { 00339 u32 data[5]; 00340 00341 data[0] = htonl(RioPktC::CMD_TELLID); 00342 data[1] = tellip; 00343 data[2] = htonl(ntohs((short) tellport)); 00344 data[3] = tellreqid; 00345 00346 #ifdef WINDOWS 00347 // Windows implementation 00348 WaitForSingleObject(d_seqlock,INFINITE); 00349 #else 00350 // Linux implementation 00351 pthread_mutex_lock(&d_seqlock); 00352 #endif 00353 /*--------------------------------- */ 00354 00355 data[4] = htonl(d_seq++); 00356 00357 #ifdef WINDOWS 00358 // Windows implementation 00359 ReleaseMutex(d_seqlock); 00360 #else 00361 // Linux implementation 00362 pthread_mutex_unlock(&d_seqlock); 00363 #endif 00364 /*--------------------------------- */ 00365 00366 d_neti->SendCmd( ipadr, port, reqid, (char *) data, 5*sizeof(data[0]), 00367 callback, callbackparm ); 00368 }
bool NetMgr::thereAreFragments | ( | RioBlock | block | ) |
Definition at line 796 of file NetMgr.cpp.
00797 { 00798 return( d_neti->thereAreFragments( block ) ); 00799 }
void* NetMgr::d_cmdparm [private] |
cmdcallback_t NetMgr::d_cmdproc [private] |
int NetMgr::d_myip [private] |
int NetMgr::d_myport [private] |
RioNeti* NetMgr::d_neti [private] |
int NetMgr::d_seq [private] |
pthread_mutex_t NetMgr::d_seqlock [private] |
CSemaphore* NetMgr::m_semalidmap [private] |
bool NetMgr::serverInstance [private] |