void *getting_thread(){ PacketDescriptor p1, p2; blocking_get_pd(fpds, &p1); blocking_get_pd(fpds, &p2); // although these last 2 lines are technically blocking in the receiving thread it is really only initialisation and should in theory never block and if it does is really blocking before everything has started init_packet_descriptor(&p1); register_receiving_packetdescriptor(netdev, &p1); await_incoming_packet(netdev); while (1){ if (nonblockingWriteBB(buffer, p1)==1){ if(nonblocking_get_pd(fpds, &p1)==0){ printf("No packet descriptors left packet dropped\n"); init_packet_descriptor(&p2); register_receiving_packetdescriptor(netdev, &p2); while(nonblocking_get_pd(fpds, &p1)==0){ await_incoming_packet(netdev); // I think this code means that if there are no packet discriptors left we can at least read from the device into a PacketDescriptor which is then overwritten until a new packet descriptor becomes available this is good because it means that the software is aware that a packet is dropped rather than just the hardware which means that the choice of handling the drop is available. } } init_packet_descriptor(&p1); register_receiving_packetdescriptor(netdev, &p1); await_incoming_packet(netdev); } else{ // at this stage again the software is aware that a packet is dropped and could potentially handle this if one were so inclined. } } return NULL; }
int nonblocking_read_sector(SectorDescriptor sd, Voucher *v) { struct voucher* vouch = (struct voucher*) malloc(sizeof(struct voucher)); vouch->sector = sd; vouch->status = -1; vouch->type = READ_REQ; pthread_mutex_init(&(vouch->voucherMutex), NULL); pthread_cond_init(&(vouch->voucherCond), NULL); *v = (Voucher) vouch; return nonblockingWriteBB(readVoucherBuffer, *v); }
int nonblocking_read_sector(SectorDescriptor sd, Voucher *v) { struct Voucher* vouch = (struct Voucher*) malloc(sizeof(struct Voucher)); pthread_mutex_init(&(vouch->vouchMut), NULL); pthread_cond_init(&(vouch->vouchCond), NULL); vouch->sector = sd; vouch->status = -1; vouch->type = READ; *v = (Voucher) vouch; int bufferStatus = nonblockingWriteBB(readBuffer, *v); //does a nonblocking add to the read buffer return bufferStatus; }
int nonblocking_send_packet(PacketDescriptor pd){//a way for applications to attempt to queue up their packets to be sent return nonblockingWriteBB(outgoing, pd); }