int main(int argc ,char *argv[]){ int i,j; int ab,c; int ecri; struct sockaddr_in local_c; socklen_t longueurAdress_c; struct sockaddr_in distant_c,distant; c=cre_socket( ); char messageEnvoi[LG_MESSAGE]; memset(messageEnvoi, 0x00, LG_MESSAGE*sizeof(char)); sprintf(messageEnvoi, "demande d'enregistrement!\n"); c=cre_socket( ); if(c< 0){ perror("socket"); // Affiche le message d’erreur exit(-1); // On sort en indiquant un code erreur } printf("Socket(serveur) créée avec succès ! (%d)\n", c); bind_socket( local_c,longueurAdress_c,c); while(1){ send_msg(distant_c,c,argv[1],argv[2],messageEnvoi); recv2(distant_c,c); } //close(c); return 0; }
//------------------------------------------------------------------- void getMinus2Data(IFloat* rcv_buf, IFloat* send_buf, int len, int mu, int nu) { IFloat *tmp_buf = (IFloat *)smalloc(len*sizeof(IFloat)); SCUDirArg send1(send_buf, pos_dir[mu], SCU_SEND, len); SCUDirArg recv1(tmp_buf, neg_dir[mu], SCU_REC, len); SCUTrans(&send1); SCUTrans(&recv1); SCUTransComplete(); SCUDirArg send2(tmp_buf, pos_dir[nu], SCU_SEND, len); SCUDirArg recv2(rcv_buf, neg_dir[nu], SCU_REC, len); SCUTrans(&send2); SCUTrans(&recv2); SCUTransComplete(); sfree(tmp_buf); }
//------------------------------------------------------------------- void getMinus3Data(IFloat* rcv_buf, IFloat* send_buf, int len, int dir) { IFloat *tmp_buf = (IFloat *)smalloc(len*sizeof(IFloat)); int i = (dir+1)%4; int j = (dir+2)%4; int k = (dir+3)%4; //-------------------------------------------------------------- // send_buf --> rcv_buf(as a temporary buffer) //-------------------------------------------------------------- SCUDirArg send1(send_buf, pos_dir[i], SCU_SEND, len); SCUDirArg recv1(rcv_buf, neg_dir[i], SCU_REC, len); SCUTrans(&send1); SCUTrans(&recv1); SCUTransComplete(); //-------------------------------------------------------------- // rcv_buf --> tmp_buf //-------------------------------------------------------------- SCUDirArg send2(rcv_buf, pos_dir[j], SCU_SEND, len); SCUDirArg recv2(tmp_buf, neg_dir[j], SCU_REC, len); SCUTrans(&send2); SCUTrans(&recv2); SCUTransComplete(); //-------------------------------------------------------------- // tmp_buf --> rcv_buf //-------------------------------------------------------------- SCUDirArg send3(tmp_buf, pos_dir[k], SCU_SEND, len); SCUDirArg recv3(rcv_buf, neg_dir[k], SCU_REC, len); SCUTrans(&send3); SCUTrans(&recv3); SCUTransComplete(); sfree(tmp_buf); }
//--------------------------------------------------------------------------- int get_message(CConceptClient *OWNER, TParameters *PARAM, SOCKET CLIENT_SOCKET, char *LOCAL_PRIVATE_KEY, PROGRESS_API notify_parent, bool idle_call) { unsigned int size2 = 0; int size = 0; int received = 0; int result = 0; int rec_count = 0; int buf_size = 0; char *buffer = 0; char *output = 0; int filemarker = 0; int MSG_ID = 0; int remaining = 0; int decrypt_result = 0; char buf_temp[0xFFFF]; if (BufferedMessages.Count()) { TParameters *clone = (TParameters *)BufferedMessages.Remove(0); PARAM->Sender = clone->Sender; PARAM->ID = clone->ID; PARAM->Target = clone->Target; PARAM->Value = clone->Value; //PARAM->Owner=clone->Owner; delete clone; return 1; } if (OWNER->RTSOCKET != INVALID_SOCKET) { if (sock_eof_timeout(OWNER->RTSOCKET, 0) == 0) { received = recv2(OWNER->RTSOCKET, buf_temp, sizeof(buf_temp), 0); size = *(unsigned int *)buf_temp; if (!LOCAL_PRIVATE_KEY) { size2 = ntohl(*(unsigned int *)&size); if (size2 & 0xF0000000) { size = size2 & 0xFFFF; } else { size = ntohl(size); size2 = 0; } } else size = ntohl(size); if ((received <= 0) || (size <= 0) /*|| (size>0xFFFF)*/) { PARAM->Sender = (char *)""; PARAM->ID = 0; PARAM->Target = (char *)""; PARAM->Value = (char *)""; return 1; } if (size > received - 4) size = received - 4; if (size) buffer = buf_temp + sizeof(int); char *out_content = 0; if ((LOCAL_PRIVATE_KEY) && (!OWNER->is_http)) { out_content = new char[size * 2]; buffer[size] = 0; decrypt_result = AES_decrypt(buffer, size, out_content, size, LOCAL_PRIVATE_KEY, 16, 0, false); out_content[decrypt_result] = 0; if (!decrypt_result) { delete[] out_content; out_content = 0; } else size = decrypt_result; } if (out_content) DeSerializeBuffer(out_content, size, &PARAM->Sender, &MSG_ID, &PARAM->Target, &PARAM->Value, size2); else DeSerializeBuffer(buffer, size, &PARAM->Sender, &MSG_ID, &PARAM->Target, &PARAM->Value, size2); // just for safety switch (MSG_ID) { case 0x1001: // event on buffer if (PARAM->Target == (char *)"350") { MSG_ID = 0x110; PARAM->Target = (char *)"103"; } else MSG_ID = -0x1001; break; case 0x110: if ((PARAM->Target != (char *)"1003") && (PARAM->Target != (char *)"1007")) MSG_ID = -0x110; break; default: MSG_ID = -0x1000; } PARAM->ID = MSG_ID; if (out_content) delete[] out_content; return size; } } do { //received = recv(CLIENT_SOCKET, (char *)&size + rec_count, sizeof(int) - rec_count, 0); received = OWNER->Recv((char *)&size + rec_count, sizeof(int) - rec_count); if (received > 0) { rec_count += received; } else { #ifdef _WIN32 if (WSAGetLastError() == WSAETIMEDOUT) #else if (errno == ETIMEDOUT) #endif return -2; CHECK_RECONNECT(received); } } while ((rec_count < sizeof(int)) && (received > 0)); if ((!LOCAL_PRIVATE_KEY) || (OWNER->is_http)) { size2 = ntohl(*(unsigned int *)&size); if (size2 & 0xF0000000) { size = size2 & 0xFFFF; } else { size = ntohl(size); size2 = 0; } } else size = ntohl(size); if (received <= 0) { if (PostFile) post_done(); return 0; } buf_size = size; char *out_content2 = 0; int initial_buf = 0; if (size) { if (PostFile) { buf_size = size > FILE_MESSAGE ? FILE_MESSAGE : size; if (size > FILE_MESSAGE) initial_buf = buf_size + 5; else initial_buf = buf_size; if (LOCAL_PRIVATE_KEY) out_content2 = new char[buf_size * 2]; } buffer = new char[buf_size + 1]; } //----------------------------------------// if ((size >= BIG_MESSAGE) && (notify_parent)) // notify big message ! notify_parent(-1, 3, idle_call); //----------------------------------------// rec_count = 0; do { if (PostFile) { if (filemarker) { remaining = size - rec_count; if (remaining > buf_size) remaining = buf_size; if (LOCAL_PRIVATE_KEY) { received = AES_recv_exact(OWNER, CLIENT_SOCKET, buffer, remaining, 0, LOCAL_PRIVATE_KEY); } else received = OWNER->Recv(buffer, remaining); //received = recv(CLIENT_SOCKET, buffer, remaining, 0); } else received = OWNER->Recv(buffer + rec_count, initial_buf - rec_count); //received = recv(CLIENT_SOCKET, buffer + rec_count, initial_buf - rec_count, 0); rec_count += received; if (received > 0) { if (filemarker) post_write(buffer, received); else if (rec_count == initial_buf) { PARAM->Sender = (char *)""; PARAM->Target = (char *)""; if (LOCAL_PRIVATE_KEY) { buffer[rec_count] = 0; decrypt_result = AES_decrypt(buffer, rec_count, out_content2, rec_count, LOCAL_PRIVATE_KEY, 16, 0, true); if (decrypt_result) { //decrypt_result -= 5;//rec_count - 5; out_content2[decrypt_result] = 0; } } int fpos = 0; if (decrypt_result > 0) { fpos = DeSerializeBuffer(out_content2, decrypt_result, &PARAM->Sender, &MSG_ID, &PARAM->Target, &PARAM->Value); if ((fpos > 0) && (fpos < decrypt_result)) post_write(out_content2 + fpos, decrypt_result - fpos); delete[] out_content2; out_content2 = 0; } else { fpos = DeSerializeBuffer(buffer, rec_count, &PARAM->Sender, &MSG_ID, &PARAM->Target, &PARAM->Value); if ((fpos > 0) && (fpos < rec_count)) post_write(buffer + fpos, rec_count - fpos); } PARAM->ID = MSG_ID; PARAM->Value.LoadBuffer(0, 0); filemarker = 1; } } else { CHECK_RECONNECT(received); } } else { //received = CConceptClient::timedout_recv(CLIENT_SOCKET, buffer + rec_count, size - rec_count, 0); received = OWNER->RecvTimeout(buffer + rec_count, size - rec_count); if (received > 0) { rec_count += received; } else { CHECK_RECONNECT(received); } } if ((size >= BIG_MESSAGE) && (notify_parent)) notify_parent((int)(((double)rec_count / size) * 100), 0, idle_call); } while ((received > 0) && (rec_count < size)); if (out_content2) { delete[] out_content2; out_content2 = 0; } if ((size >= BIG_MESSAGE) && (notify_parent)) notify_parent(101, 0, idle_call); // done big message ! if (received <= 0) { if (buffer) delete[] buffer; return 0; } if (PostFile) post_done(); else { char *out_content = 0; if ((LOCAL_PRIVATE_KEY) && (!OWNER->is_http)) { out_content = new char[size * 2]; buffer[size] = 0; decrypt_result = AES_decrypt(buffer, size, out_content, size, LOCAL_PRIVATE_KEY, 16, 0, true); out_content[decrypt_result] = 0; if (!decrypt_result) { delete[] out_content; out_content = 0; } else size = decrypt_result; } if (out_content) DeSerializeBuffer(out_content, size, &PARAM->Sender, &MSG_ID, &PARAM->Target, &PARAM->Value, size2); else DeSerializeBuffer(buffer, size, &PARAM->Sender, &MSG_ID, &PARAM->Target, &PARAM->Value, size2); PARAM->ID = MSG_ID; if (out_content) delete[] out_content; } if (buffer) delete[] buffer; return size; }
void start() { ACPI_STATUS status = AE_OK; printf("acpica: starting...\n"); // NB! Must be at least as large as physical memory - the ACPI tables could // be anywhere. (Could be handled by AcpiOsMapMemory though.) map(0, MAP_PHYS | PROT_READ | PROT_WRITE | PROT_NO_CACHE, (void*)ACPI_PHYS_BASE, 0, USER_MAP_MAX - ACPI_PHYS_BASE); __default_section_init(); AcpiDbgLayer = 0; AcpiDbgLevel = ACPI_LV_REPAIR | ACPI_LV_INTERRUPTS; status = InitializeFullAcpi (); CHECK_STATUS("InitializeFullAcpi"); int pic_mode = 0; // Default is PIC mode if something fails status = PrintAPICTable(); CHECK_STATUS("PrintAPICTable"); status = FindIOAPICs(&pic_mode); CHECK_STATUS("Find IOAPIC"); status = ExecuteOSI(pic_mode); CHECK_STATUS("ExecuteOSI"); // Tables we get in Bochs: // * DSDT: All the AML code // * FACS // * FACP // * APIC (= MADT) // * SSDT: Secondary System Description Table // Contains more AML code loaded automatically by ACPICA // More tables on qemu: // * Another SSDT (Loaded by ACPICA) // * HPET table // PrintFACSTable(); // PrintFACPTable(); // TODO Iterate through and disable all pci interrupt link devices (call // _DIS). Then we'll enable the ones we actually intend to use. EnumeratePCI(); AcpiWriteBitRegister(ACPI_BITREG_SCI_ENABLE, 1); //AcpiWriteBitRegister(ACPI_BITREG_POWER_BUTTON_ENABLE, 1); AcpiInstallGlobalEventHandler(GlobalEventHandler, NULL); AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, 0); for (;;) { ipc_dest_t rcpt = 0x100; ipc_arg_t arg = 0; ipc_arg_t arg2 = 0; ipc_msg_t msg = recv2(&rcpt, &arg, &arg2); //printf("acpica: Received %#lx from %#lx: %#lx %#lx\n", msg, rcpt, arg, arg2); if (msg == MSG_PULSE) { if (AcpiOsCheckInterrupt(rcpt, arg)) { continue; } else { printf("acpica: Unhandled pulse: %#x from %#lx\n", arg, rcpt); } } switch (msg & 0xff) { case MSG_ACPI_FIND_PCI: MsgFindPci(rcpt, arg); break; case MSG_ACPI_CLAIM_PCI: MsgClaimPci(rcpt, arg, arg2); break; // This feels a bit wrong, but as long as we use PIO access to PCI // configuration space, we need to serialize all accesses. case MSG_ACPI_READ_PCI: arg = PciReadWord((arg & 0x7ffffffc) | 0x80000000); send1(MSG_ACPI_READ_PCI, rcpt, arg); break; case MSG_ACPI_DEBUGGER_INIT: debugger_pre_cmd(); send0(MSG_ACPI_DEBUGGER_INIT, rcpt); break; case MSG_ACPI_DEBUGGER_BUFFER: assert(debugger_buffer_pos < ACPI_DB_LINE_BUFFER_SIZE); AcpiGbl_DbLineBuf[debugger_buffer_pos++] = arg; send0(MSG_ACPI_DEBUGGER_BUFFER, rcpt); break; case MSG_ACPI_DEBUGGER_CMD: assert(debugger_buffer_pos < ACPI_DB_LINE_BUFFER_SIZE); AcpiGbl_DbLineBuf[debugger_buffer_pos++] = 0; putchar('\n'); AcpiDbCommandDispatch(AcpiGbl_DbLineBuf, NULL, NULL); debugger_pre_cmd(); send0(MSG_ACPI_DEBUGGER_CMD, rcpt); break; case MSG_ACPI_DEBUGGER_CLR_BUFFER: debugger_pre_cmd(); send0(MSG_ACPI_DEBUGGER_CLR_BUFFER, rcpt); break; case MSG_REG_IRQ: RegIRQ(rcpt, arg); continue; case MSG_IRQ_ACK: AckIRQ(rcpt); continue; } // TODO Handle other stuff. if (rcpt == 0x100) { hmod(rcpt, 0, 0); } } __builtin_unreachable(); failed: printf("ACPI failed :( (status %x)\n", status); abort(); }