Add sleeping on accept & read
This commit is contained in:
parent
bb79c9c090
commit
a245c21d71
@ -254,7 +254,7 @@ void schedule(struct regs *r) {
|
|||||||
kprintf("PID %d Corrupted CR3 %p Current Task %d\n", current_task->next_task->pid, current_task->next_task->cr3, current_task->pid);
|
kprintf("PID %d Corrupted CR3 %p Current Task %d\n", current_task->next_task->pid, current_task->next_task->cr3, current_task->pid);
|
||||||
}
|
}
|
||||||
if (current_task->state == TASK_ZOMBIE) {
|
if (current_task->state == TASK_ZOMBIE) {
|
||||||
if (current_task->parent_task->state = TASK_WAITING) {
|
if (current_task->parent_task->state == TASK_WAITING) {
|
||||||
wait_return = (unsigned int *)(current_task->parent_task->esp + 44);
|
wait_return = (unsigned int *)(current_task->parent_task->esp + 44);
|
||||||
status = (unsigned int *)(current_task->parent_task->esp + 32);
|
status = (unsigned int *)(current_task->parent_task->esp + 32);
|
||||||
|
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
#define TASK_SEM_WAIT 6
|
#define TASK_SEM_WAIT 6
|
||||||
#define TASK_ZOMBIE 7
|
#define TASK_ZOMBIE 7
|
||||||
|
|
||||||
|
#define SLEEP_USER 1
|
||||||
|
#define SLEEP_TCP_ACCEPT 2
|
||||||
|
#define SLEEP_TCP_READ 3
|
||||||
|
|
||||||
#ifndef KRNL_STACK_SIZE
|
#ifndef KRNL_STACK_SIZE
|
||||||
# define KRNL_STACK_SIZE 0x4000
|
# define KRNL_STACK_SIZE 0x4000
|
||||||
#endif
|
#endif
|
||||||
@ -66,6 +70,7 @@ struct task_t {
|
|||||||
struct socket_t *waiting_sockets[25];
|
struct socket_t *waiting_sockets[25];
|
||||||
int waiting_socket_count;
|
int waiting_socket_count;
|
||||||
unsigned int exit_status;
|
unsigned int exit_status;
|
||||||
|
int sleep_reason;
|
||||||
char zombie_ttl;
|
char zombie_ttl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
7
socket.c
7
socket.c
@ -114,6 +114,9 @@ struct socket_t *socket_find(unsigned int dport, unsigned int sport, unsigned in
|
|||||||
|
|
||||||
new_socket->status = 0;
|
new_socket->status = 0;
|
||||||
task->waiting_sockets[task->waiting_socket_count++] = new_socket;
|
task->waiting_sockets[task->waiting_socket_count++] = new_socket;
|
||||||
|
if (task->state == TASK_SLEEPING && task->sleep_reason == SLEEP_TCP_ACCEPT) {
|
||||||
|
task->state = TASK_RUNNING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -211,6 +214,8 @@ int socket_read(struct socket_t *sock, char *buffer, int len) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sock->offset = offset;
|
sock->offset = offset;
|
||||||
|
((struct task_t *)sock->data)->sleep_reason = SLEEP_TCP_READ;
|
||||||
|
((struct task_t *)sock->data)->state = TASK_SLEEPING;
|
||||||
return -1; // return -1 to signal retry.
|
return -1; // return -1 to signal retry.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,6 +483,8 @@ struct socket_t *socket_accept(struct socket_t *socket, struct inet_addr *client
|
|||||||
}
|
}
|
||||||
return new_socket;
|
return new_socket;
|
||||||
}
|
}
|
||||||
|
task->state = TASK_SLEEPING;
|
||||||
|
task->sleep_reason = SLEEP_TCP_ACCEPT;
|
||||||
|
|
||||||
return (void *)0;
|
return (void *)0;
|
||||||
}
|
}
|
||||||
|
@ -229,6 +229,9 @@ void syscall_isr(struct regs *r) {
|
|||||||
break;
|
break;
|
||||||
case SYS_SOCK_READ:
|
case SYS_SOCK_READ:
|
||||||
r->eax = socket_read((struct socket_t *)r->ebx, (char *)r->ecx, r->edx);
|
r->eax = socket_read((struct socket_t *)r->ebx, (char *)r->ecx, r->edx);
|
||||||
|
if (r->eax == -1) {
|
||||||
|
schedule(r);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SYS_SOCK_WRITE:
|
case SYS_SOCK_WRITE:
|
||||||
r->eax = socket_write((struct socket_t*)r->ebx, (unsigned char*)r->ecx, r->edx);
|
r->eax = socket_write((struct socket_t*)r->ebx, (unsigned char*)r->ecx, r->edx);
|
||||||
@ -238,6 +241,9 @@ void syscall_isr(struct regs *r) {
|
|||||||
break;
|
break;
|
||||||
case SYS_SOCK_ACCEPT:
|
case SYS_SOCK_ACCEPT:
|
||||||
r->eax = (unsigned int)socket_accept((struct socket_t *)r->ebx, (struct inet_addr *)r->ecx);
|
r->eax = (unsigned int)socket_accept((struct socket_t *)r->ebx, (struct inet_addr *)r->ecx);
|
||||||
|
if (r->eax == (void *)0) {
|
||||||
|
schedule(r);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SYS_MEM_INFO:
|
case SYS_MEM_INFO:
|
||||||
r->eax = mem_get_info((struct mem_info *)r->ebx);
|
r->eax = mem_get_info((struct mem_info *)r->ebx);
|
||||||
|
4
tcp.c
4
tcp.c
@ -84,6 +84,10 @@ void tcp_process_packet(struct ether_t *ether, unsigned int dest, unsigned int s
|
|||||||
|
|
||||||
|
|
||||||
if (sock != (void *)0) {
|
if (sock != (void *)0) {
|
||||||
|
if (((struct task_t *)sock->data)->state == TASK_SLEEPING && ((struct task_t *)sock->data)->sleep_reason == SLEEP_TCP_READ) {
|
||||||
|
((struct task_t *)sock->data)->state = TASK_RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
if ((htons(packet->flags) & TCP_FLAGS_FIN) && (htons(packet->flags) & TCP_FLAGS_ACK)) {
|
if ((htons(packet->flags) & TCP_FLAGS_FIN) && (htons(packet->flags) & TCP_FLAGS_ACK)) {
|
||||||
sock->tcp_sock.ack_number = htonl(packet->seq_number) + 1;
|
sock->tcp_sock.ack_number = htonl(packet->seq_number) + 1;
|
||||||
tcp_send(ether, sock, TCP_FLAGS_ACK, (void *)0, 0);
|
tcp_send(ether, sock, TCP_FLAGS_ACK, (void *)0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user