Use the service thread for comm notifications.
This commit is contained in:
parent
a1089c59b9
commit
c9c2a59c62
|
@ -18,6 +18,7 @@ struct DosDeviceStruct {
|
||||||
unsigned obuf_size,obuf_head,obuf_tail;
|
unsigned obuf_size,obuf_head,obuf_tail;
|
||||||
/* notifications */
|
/* notifications */
|
||||||
int wnd, n_read, n_write;
|
int wnd, n_read, n_write;
|
||||||
|
HANDLE service;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void COMM_Init(void);
|
extern void COMM_Init(void);
|
||||||
|
|
24
misc/comm.c
24
misc/comm.c
|
@ -64,7 +64,8 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "winerror.h"
|
#include "winerror.h"
|
||||||
#include "async.h"
|
#include "services.h"
|
||||||
|
#include "file.h"
|
||||||
|
|
||||||
#include "debugtools.h"
|
#include "debugtools.h"
|
||||||
|
|
||||||
|
@ -213,12 +214,12 @@ static int COMM_WhackModem(int fd, unsigned int andy, unsigned int orrie)
|
||||||
return ioctl(fd, TIOCMSET, &mstat);
|
return ioctl(fd, TIOCMSET, &mstat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void comm_notification(int fd,void*private)
|
static void CALLBACK comm_notification( ULONG_PTR private )
|
||||||
{
|
{
|
||||||
struct DosDeviceStruct *ptr = (struct DosDeviceStruct *)private;
|
struct DosDeviceStruct *ptr = (struct DosDeviceStruct *)private;
|
||||||
int prev, bleft, len;
|
int prev, bleft, len;
|
||||||
WORD mask = 0;
|
WORD mask = 0;
|
||||||
int cid = GetCommPort_fd(fd);
|
int cid = GetCommPort_fd(ptr->fd);
|
||||||
|
|
||||||
TRACE("async notification\n");
|
TRACE("async notification\n");
|
||||||
/* read data from comm port */
|
/* read data from comm port */
|
||||||
|
@ -226,7 +227,7 @@ static void comm_notification(int fd,void*private)
|
||||||
do {
|
do {
|
||||||
bleft = ((ptr->ibuf_tail > ptr->ibuf_head) ? (ptr->ibuf_tail-1) : ptr->ibuf_size)
|
bleft = ((ptr->ibuf_tail > ptr->ibuf_head) ? (ptr->ibuf_tail-1) : ptr->ibuf_size)
|
||||||
- ptr->ibuf_head;
|
- ptr->ibuf_head;
|
||||||
len = read(fd, ptr->inbuf + ptr->ibuf_head, bleft?bleft:1);
|
len = read(ptr->fd, ptr->inbuf + ptr->ibuf_head, bleft?bleft:1);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if (!bleft) {
|
if (!bleft) {
|
||||||
ptr->commerror = CE_RXOVER;
|
ptr->commerror = CE_RXOVER;
|
||||||
|
@ -257,7 +258,7 @@ static void comm_notification(int fd,void*private)
|
||||||
|
|
||||||
/* write any TransmitCommChar character */
|
/* write any TransmitCommChar character */
|
||||||
if (ptr->xmit>=0) {
|
if (ptr->xmit>=0) {
|
||||||
len = write(fd, &(ptr->xmit), 1);
|
len = write(ptr->fd, &(ptr->xmit), 1);
|
||||||
if (len > 0) ptr->xmit = -1;
|
if (len > 0) ptr->xmit = -1;
|
||||||
}
|
}
|
||||||
/* write from output queue */
|
/* write from output queue */
|
||||||
|
@ -265,7 +266,7 @@ static void comm_notification(int fd,void*private)
|
||||||
do {
|
do {
|
||||||
bleft = ((ptr->obuf_tail <= ptr->obuf_head) ? ptr->obuf_head : ptr->obuf_size)
|
bleft = ((ptr->obuf_tail <= ptr->obuf_head) ? ptr->obuf_head : ptr->obuf_size)
|
||||||
- ptr->obuf_tail;
|
- ptr->obuf_tail;
|
||||||
len = bleft ? write(fd, ptr->outbuf + ptr->obuf_tail, bleft) : 0;
|
len = bleft ? write(ptr->fd, ptr->outbuf + ptr->obuf_tail, bleft) : 0;
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
ptr->obuf_tail += len;
|
ptr->obuf_tail += len;
|
||||||
if (ptr->obuf_tail >= ptr->obuf_size)
|
if (ptr->obuf_tail >= ptr->obuf_size)
|
||||||
|
@ -455,10 +456,12 @@ INT16 WINAPI OpenComm16(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
|
||||||
return IE_MEMORY;
|
return IE_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* enable async notifications */
|
COM[port].service = SERVICE_AddObject( FILE_DupUnixHandle( COM[port].fd,
|
||||||
ASYNC_RegisterFD(COM[port].fd,comm_notification,&COM[port]);
|
GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE ),
|
||||||
|
comm_notification,
|
||||||
|
(ULONG_PTR)&COM[port] );
|
||||||
/* bootstrap notifications, just in case */
|
/* bootstrap notifications, just in case */
|
||||||
comm_notification(COM[port].fd,&COM[port]);
|
comm_notification( (ULONG_PTR)&COM[port] );
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,8 +502,7 @@ INT16 WINAPI CloseComm16(INT16 cid)
|
||||||
/* COM port */
|
/* COM port */
|
||||||
SEGPTR_FREE(unknown[cid]); /* [LW] */
|
SEGPTR_FREE(unknown[cid]); /* [LW] */
|
||||||
|
|
||||||
/* disable async notifications */
|
SERVICE_Delete( COM[cid].service );
|
||||||
ASYNC_UnregisterFD(COM[cid].fd,comm_notification);
|
|
||||||
/* free buffers */
|
/* free buffers */
|
||||||
free(ptr->outbuf);
|
free(ptr->outbuf);
|
||||||
free(ptr->inbuf);
|
free(ptr->inbuf);
|
||||||
|
|
Loading…
Reference in New Issue