void handle_client_message(connection_info clients[], int sender) { int read_size; SBCP_message msg; if((read_size = recv(clients[sender].socket, &msg, sizeof(msg), 0)) == 0) { printf("User disconnected: %s.\n", clients[sender].username); close(clients[sender].socket); clients[sender].socket = 0; clients[sender].username[0] = 0; //send_disconnect_message(clients, clients[sender].username); } else { // interprete msg header_type h_type = getHeaderType( msg ); switch(h_type) { case JOIN: ; // JOIN // duplicated name char tempname[21]; getUsername(msg, tempname); int i; for(i = 0; i < MAX_CLIENTS; i++) { if(strcmp(clients[i].username, tempname) == 0) { puts("Dected one duplicated usename"); send_duplicated_name(clients[sender].socket); close(clients[sender].socket); clients[sender].socket = 0; return; } } puts("Server detected one JOIN"); strcpy(clients[sender].username, tempname); printf("User connected: %s\n", clients[sender].username); //send_connect_message(clients, sender); break; case SEND: puts("Server detected one SEND"); char msg_content[256]; getMessageContent(msg, msg_content); send_public_message(clients, sender, msg_content); //TODO break; default: fprintf(stderr, "Unknown message type received.\n"); break; } } }
/*! * Calculates the offsets of all geometry and data fields for appended output. * Offsets are stored in each field. */ void VTK::calcAppendedOffsets(){ uint64_t offset(0) ; uint64_t HeaderByte ; if( getHeaderType() == "UInt32"){ HeaderByte = sizeof(uint32_t) ; } else if( getHeaderType() == "UInt64") { HeaderByte = sizeof(uint64_t) ; }; for( auto & field : data ){ if( field->getCodification() == VTKFormat::APPENDED && field->getLocation() == VTKLocation::POINT ) { field->setOffset( offset) ; offset += HeaderByte + field->getNbytes() ; }; }; for( auto & field : data ){ if( field->getCodification() == VTKFormat::APPENDED && field->getLocation() == VTKLocation::CELL) { field->setOffset( offset) ; offset += HeaderByte + field->getNbytes() ; }; }; for( auto & field : geometry ){ if( field->getCodification() == VTKFormat::APPENDED ) { field->setOffset( offset) ; offset += HeaderByte + field->getNbytes() ; }; }; return ; };
void PCI::scan_devices() { int device_count = 0; for (uint32_t bus = 0; bus < 256; bus++) { for (uint32_t slot = 0; slot < 32; slot++) { for (uint32_t function = 0; function < 8; function++) { //根据配置空间的第0个寄存器是否返回0FFFFH值来判断是否存在该PCI设备 uint32_t vendor = getVendorID(bus, slot, function); if (vendor == 0xffff) break; uint32_t device = getDeviceID(bus, slot, function); uint32_t baseclass = getBaseClass(bus, slot, function); uint32_t subclass = getSubClass(bus, slot, function); uint32_t progif = getProgIF(bus, slot, function); PCI_IDS* pci_ids = get_device_ids(vendor, device, 0, 0); PCI_DEVICE_CLASS* pci_class = get_device_class(baseclass, subclass, progif); if (pci_ids != NULL) { printf("%d %02X:%02X:%X device: %s\n", device_count++, bus, slot, function, pci_ids->device_name); } else { printf("%d %02X:%02X:%X vendor: %x device: %x class: %x subclass: %x \n", device_count++, bus, slot, function, vendor, device, baseclass, subclass); } uint32_t header_type = getHeaderType(bus, slot, function); if ( (header_type & 0x80) == 0) break; /*pci_device *pdev = (pci_device *)malloc(sizeof(pci_device)); pdev->vendor = vendor; pdev->device = device; pdev->func = function; pdev->driver = 0; add_pci_device(pdev);*/ } } } }
void handle_server_message(connection_info *connection) { SBCP_message msg; // message msg; //Receive a reply from the server ssize_t recv_val = recv(connection->socket, &msg, sizeof(msg), 0); if(recv_val < 0) { perror("recv failed"); exit(1); } else if(recv_val == 0) { close(connection->socket); puts("Server disconnected."); exit(0); } header_type h_type = getHeaderType( msg); switch(h_type) { case FWD:; char username[20]; char msg_content[256]; getUsername(msg, username); getMessageContent(msg, msg_content); printf("%s: %s\n", username, msg_content); break; case NAK:; char corresponding_text[512]; getCorrespondingAttr(msg, corresponding_text, Reason ); // printf("%s\n",corresponding_text); close(connection->socket); exit(0); break; default: fprintf(stderr, "Unknown message type received.\n"); break; } }
/*! * Writes data only in VTK file */ void VTK::writeData( ){ std::fstream str ; std::fstream::pos_type position_insert, position_eof ; int length; char* buffer ; str.open( fh.getPath( ), std::ios::in | std::ios::out ) ; { // Write Ascii position_insert = str.tellg(); VTKField temp ; //Writing first point data then cell data for( auto &field : data ){ if( field->getCodification() == VTKFormat::ASCII && field->getLocation() == VTKLocation::POINT ) { str.seekg( position_insert); readDataArray( str, *field ) ; str.seekg( field->getPosition() ) ; genericIO::copyUntilEOFInString( str, buffer, length ); writeFieldData( str, *field) ; position_insert = str.tellg(); str << std::endl ; genericIO::flushBINARY( str, buffer, length) ; delete [] buffer ; }; }; for( auto &field : data ){ if( field->getCodification() == VTKFormat::ASCII && field->getLocation() == VTKLocation::CELL ) { str.seekg( position_insert); readDataArray( str, *field ) ; str.seekg( field->getPosition() ) ; genericIO::copyUntilEOFInString( str, buffer, length ); writeFieldData( str, *field) ; position_insert = str.tellg(); str << std::endl ; genericIO::flushBINARY( str, buffer, length) ; delete [] buffer ; }; }; for( auto &field : geometry ){ if( field->getCodification() == VTKFormat::ASCII ) { str.seekg( position_insert); readDataArray( str, *field ) ; str.seekg( field->getPosition() ) ; genericIO::copyUntilEOFInString( str, buffer, length ); writeFieldData( str, *field) ; //flushData( str, VTKFormat::ASCII, field.getName() ) ; position_insert = str.tellg(); str << std::endl ; genericIO::flushBINARY( str, buffer, length) ; delete [] buffer ; }; }; str.seekg( temp.getPosition() ) ; } { // Write Appended char c_; std::string line ; std::fstream::pos_type position_appended ; //Go to the initial position of the appended section while( getline(str, line) && (! bitpit::utils::keywordInString( line, "<AppendedData")) ){} ; str >> c_; while( c_ != '_') str >> c_; position_insert = str.tellg(); genericIO::copyUntilEOFInString( str, buffer, length ); str.close(); str.clear(); //Reopening in binary mode str.open( fh.getPath( ), std::ios::out | std::ios::in | std::ios::binary); str.seekg( position_insert) ; //str.open( "data.dat", std::ios::out | std::ios::binary); //Writing first point data then cell data for( auto &field : data ){ if( field->getCodification() == VTKFormat::APPENDED && field->getLocation() == VTKLocation::POINT ) { if( getHeaderType() == "UInt32"){ uint32_t nbytes = field->getNbytes() ; genericIO::flushBINARY(str, nbytes) ; } else{ uint64_t nbytes = field->getNbytes() ; genericIO::flushBINARY(str, nbytes) ; }; writeFieldData( str, *field) ; }; } for( auto &field : data ){ if( field->getCodification() == VTKFormat::APPENDED && field->getLocation() == VTKLocation::CELL ) { if( getHeaderType() == "UInt32"){ uint32_t nbytes = field->getNbytes() ; genericIO::flushBINARY(str, nbytes) ; } else{ uint64_t nbytes = field->getNbytes() ; genericIO::flushBINARY(str, nbytes) ; }; writeFieldData( str, *field) ; }; } //Writing Geometry Data for( auto &field : geometry ){ if( field->getCodification() == VTKFormat::APPENDED ) { if( getHeaderType() == "UInt32"){ uint32_t nbytes = field->getNbytes() ; genericIO::flushBINARY(str, nbytes) ; } else{ uint64_t nbytes = field->getNbytes() ; genericIO::flushBINARY(str, nbytes) ; }; writeFieldData( str, *field) ; }; }; //{ //std::fstream str2 ; //str2.open( "test2.dat", std::ios::out | std::ios::binary); //genericIO::flushBINARY( str2, buffer, length) ; //str2.close(); //} genericIO::flushBINARY( str, buffer, length) ; delete [] buffer ; }; // Closing Appended Secyion str.close(); return ; };