/* * OrderedEnqueue */ static RC OrderedEnqueue(TD* td, LL* list, int(*getorder)(TD* td)){ // TD will be in the given list td->inlist = list; // See if we are the new head if(!list->head || getorder(td) < getorder(list->head)) { if(list->head) td->link = list->head; list->head = td; return 0; } // Search for a place to insert TD* prev; for(prev = list->head; prev->link; prev = prev->link) if(getorder(td) < getorder(prev->link)) break; // Perform the insertion td->link = prev->link; prev->link = td; return 0; }
/* * OrderedEnqueue */ static RC OrderedEnqueue(struct PD* pd, struct LL* list, int(*getorder)(struct PD* pd)){ // PD will be in the given list pd->inlist = list; // See if we are the new head if(!list->head || getorder(pd) < getorder(list->head)) { if(list->head) pd->link = list->head; list->head = pd; return 0; } // Search for a place to insert struct PD* prev; for(prev = list->head; prev->link; prev = prev->link) if(getorder(pd) < getorder(prev->link)) break; // Perform the insertion pd->link = prev->link; prev->link = pd; return 0; }
int main() { //启动客户端,连接服务器,得到socket描述符 int st = startclient(); //输入请求并发送,order存放请求选项 while (1) { //输入请求,错误则重新输入 int order = getorder(); if (order == -1) { continue; } //将请求信息发送给服务器 send(st, &order, sizeof(order), 0); //选项1代表下载文件 if (order == 1) { download(st); } //选项2代表上传文件 if (order == 2) { upload(st); } //选项3代表关闭连接 if (order == 3) { close(st); break; } } return 0; }