Make socket port binding a separate step with ipc_netsockbindport() syscall
This commit is contained in:
@ -72,7 +72,7 @@ void ipc_netsock_event(uint16_t ev, struct pico_socket *sock1) {
|
||||
spinlock_release(&netsock->spinlock);
|
||||
}
|
||||
|
||||
IpcNetSock *ipc_netsockmake(uint16_t net, uint16_t proto, uint16_t port, uint64_t pid) {
|
||||
IpcNetSock *ipc_netsockmake(uint16_t net, uint16_t proto, uint64_t pid) {
|
||||
IpcNetSock *netsock = dlmalloc(sizeof(*netsock));
|
||||
if (netsock == NULL) {
|
||||
return NULL;
|
||||
@ -92,10 +92,6 @@ IpcNetSock *ipc_netsockmake(uint16_t net, uint16_t proto, uint16_t port, uint64_
|
||||
|
||||
netsock->ownerpid = pid;
|
||||
|
||||
uint16_t port_be = short_be(port);
|
||||
struct pico_ip4 inaddr_any = {0};
|
||||
pico_socket_bind(netsock->picosock, &inaddr_any, &port_be);
|
||||
|
||||
spinlock_acquire(&IPC_NETSOCKS.spinlock);
|
||||
LL_APPEND(IPC_NETSOCKS.netsocks, netsock);
|
||||
spinlock_release(&IPC_NETSOCKS.spinlock);
|
||||
@ -144,6 +140,18 @@ int32_t ipc_netsockdelete(IpcNetSock *netsock) {
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
int32_t ipc_netsockbindport(IpcNetSock *netsock, uint16_t port) {
|
||||
uint16_t port_be = short_be(port);
|
||||
struct pico_ip4 inaddr_any = {0};
|
||||
spinlock_acquire(&netsock->spinlock);
|
||||
int32_t r = pico_socket_bind(netsock->picosock, &inaddr_any, &port_be);
|
||||
spinlock_release(&netsock->spinlock);
|
||||
if (r != 0) {
|
||||
return E_NETSOCKBIND;
|
||||
}
|
||||
return E_OK;
|
||||
}
|
||||
|
||||
void ipc_netsock_cleanup_dangling(void) {
|
||||
IpcNetSock *ns, *nstmp;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user