mirror of
https://github.com/ksherlock/marignotti.git
synced 2024-12-11 17:51:04 +00:00
new write function
This commit is contained in:
parent
1f6030f867
commit
b127812ccc
58
mwrite.c
Normal file
58
mwrite.c
Normal file
@ -0,0 +1,58 @@
|
||||
#include "marignotti.h"
|
||||
#include <gno/kerntool.h>
|
||||
#include <sys/signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
#pragma noroot
|
||||
#pragma optimize 79
|
||||
|
||||
// called through GSOS.
|
||||
int mwrite(int ipid, void *p1, void *p2, void *p3, void *p4, void *p5)
|
||||
{
|
||||
Entry *e;
|
||||
Word terr;
|
||||
Word t;
|
||||
int xerrno;
|
||||
|
||||
char *buffer = (char *)p1;
|
||||
LongWord nbytes = *(LongWord *)p2;
|
||||
|
||||
*(LongWord *)p2 = 0;
|
||||
|
||||
e = find_entry(ipid);
|
||||
|
||||
if (!e)
|
||||
{
|
||||
return EBADF;
|
||||
}
|
||||
|
||||
// todo -- queue up if pending >= _SNDLOWAT?
|
||||
// todo -- push?
|
||||
|
||||
IncBusy();
|
||||
terr = TCPIPWriteTCP(ipid, buffer, nbytes, 0, 0);
|
||||
t = _toolErr;
|
||||
DecBusy();
|
||||
|
||||
if (t) terr = t;
|
||||
|
||||
if (t || terr == tcperrBadConnection)
|
||||
return ENOTCONN;
|
||||
|
||||
if (terr == tcperrNoResources)
|
||||
return ENOMEM;
|
||||
|
||||
if (terr == tcperrConClosing)
|
||||
{
|
||||
int xerrno;
|
||||
if (!e->_NOSIGPIPE)
|
||||
Kkill(Kgetpid(), SIGPIPE, &xerrno);
|
||||
|
||||
return EPIPE;
|
||||
}
|
||||
|
||||
*(LongWord *)p2 = nbytes;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user