mirror of https://github.com/macssh/macssh.git
use current thread context in GUSITTY
This commit is contained in:
parent
a77d339722
commit
870775005f
Binary file not shown.
|
@ -29,7 +29,6 @@
|
|||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
/*#include <errno.h>*/
|
||||
|
||||
|
||||
class GUSITTYDevice : public GUSIDevice {
|
||||
|
@ -78,10 +77,10 @@ public:
|
|||
bool select(bool * canRead, bool * canWrite, bool *);
|
||||
|
||||
protected:
|
||||
GUSITTYSocket(int id, int flags);
|
||||
GUSITTYSocket(int id, void *context);
|
||||
|
||||
int mId;
|
||||
int mFlags;
|
||||
void *mContext;
|
||||
|
||||
friend class GUSITTYDevice;
|
||||
};
|
||||
|
@ -150,7 +149,7 @@ GUSISocket * GUSITTYDevice::open(GUSIFileToken &file, int flags)
|
|||
} else /*if (file.StrFragEqual(path+7, "err"))*/ {
|
||||
id = 2;
|
||||
}
|
||||
if ( !(sock = new GUSITTYSocket(id, flags) )) {
|
||||
if ( !(sock = new GUSITTYSocket(id, pthread_getspecific(ssh2threadkey)) )) {
|
||||
GUSISetPosixError(ENOMEM);
|
||||
}
|
||||
return sock;
|
||||
|
@ -161,9 +160,9 @@ GUSISocket * GUSITTYDevice::open(GUSIFileToken &file, int flags)
|
|||
/*
|
||||
* GUSITTYSocket::GUSITTYSocket
|
||||
*/
|
||||
GUSITTYSocket::GUSITTYSocket(int id, int flags) : mId(id), mFlags(flags)
|
||||
GUSITTYSocket::GUSITTYSocket(int id, void *context) : mId(id), mContext(context)
|
||||
{
|
||||
InstallTTY(id, flags);
|
||||
InstallTTY(id, context);
|
||||
}
|
||||
|
||||
|
||||
|
@ -172,7 +171,7 @@ GUSITTYSocket::GUSITTYSocket(int id, int flags) : mId(id), mFlags(flags)
|
|||
*/
|
||||
GUSITTYSocket::~GUSITTYSocket()
|
||||
{
|
||||
RemoveTTY(mId, mFlags);
|
||||
RemoveTTY(mId, mContext);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -183,7 +182,7 @@ ssize_t GUSITTYSocket::read(const GUSIScatterer & buffer)
|
|||
/* FIXME: flush pending output */
|
||||
/*FlushTTY(mId);*/
|
||||
return buffer.SetLength(
|
||||
ReadCharsFromTTY(mId, mFlags, (char *) buffer.Buffer(), (int)buffer.Length()));
|
||||
ReadCharsFromTTY(mId, mContext, (char *) buffer.Buffer(), (int)buffer.Length()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -191,7 +190,7 @@ ssize_t GUSITTYSocket::read(const GUSIScatterer & buffer)
|
|||
*/
|
||||
ssize_t GUSITTYSocket::write(const GUSIGatherer & buffer)
|
||||
{
|
||||
return WriteCharsToTTY(mId, mFlags, (char *) buffer.Buffer(), (int)buffer.Length());
|
||||
return WriteCharsToTTY(mId, mContext, (char *) buffer.Buffer(), (int)buffer.Length());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -233,7 +232,7 @@ bool GUSITTYSocket::select(bool * canRead, bool * canWrite, bool *)
|
|||
{
|
||||
bool cond = false;
|
||||
if (canRead)
|
||||
if (*canRead = AvailableFromTTY(mId, mFlags))
|
||||
if (*canRead = AvailableFromTTY(mId, mContext))
|
||||
cond = true;
|
||||
if (canWrite)
|
||||
cond = *canWrite = true;
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
#ifndef _GUSITTY_
|
||||
#define _GUSITTY_
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int InstallTTY(int id, int flags);
|
||||
extern void RemoveTTY(int id, int flags);
|
||||
extern int ReadCharsFromTTY(int id, int flags, char * buffer, int length);
|
||||
extern int WriteCharsToTTY(int id, int flags, char * buffer, int length);
|
||||
extern int AvailableFromTTY(int id, int flags);
|
||||
extern pthread_key_t ssh2threadkey;
|
||||
|
||||
extern int InstallTTY(int id, void *context);
|
||||
extern void RemoveTTY(int id, void *context);
|
||||
extern int ReadCharsFromTTY(int id, void *context, char * buffer, int length);
|
||||
extern int WriteCharsToTTY(int id, void *context, char * buffer, int length);
|
||||
extern int AvailableFromTTY(int id, void *context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -544,30 +544,37 @@ pascal Ptr PLstrrchr(ConstStr255Param s, short c)
|
|||
/*
|
||||
* InstallTTY
|
||||
*/
|
||||
int InstallTTY(int fd, int flags)
|
||||
int InstallTTY(int id, void *ctx)
|
||||
{
|
||||
#pragma unused (fd)
|
||||
#pragma unused (id, ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* RemoveTTY
|
||||
*/
|
||||
void RemoveTTY(int fd, int flags)
|
||||
void RemoveTTY(int fd, void *ctx)
|
||||
{
|
||||
#pragma unused (fd)
|
||||
#pragma unused (id, ctx)
|
||||
}
|
||||
|
||||
/*
|
||||
* WriteCharsToTTY
|
||||
*/
|
||||
int WriteCharsToTTY(int fd, int flags, char *buffer, int n)
|
||||
int WriteCharsToTTY(int id, void *ctx, char *buffer, int n)
|
||||
{
|
||||
long written = 0;
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
lshcontext *context = (lshcontext *)ctx;
|
||||
char *buf = buffer;
|
||||
char c;
|
||||
|
||||
if ( id == 2 ) {
|
||||
// log stderr to console
|
||||
syslog( 0, "%.*s", n, buffer );
|
||||
/*putlln( buffer, n );*/
|
||||
return n;
|
||||
}
|
||||
|
||||
if ( !context ) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -634,10 +641,11 @@ int WriteCharsToTTY(int fd, int flags, char *buffer, int n)
|
|||
/*
|
||||
* ReadCharsFromTTY
|
||||
*/
|
||||
int ReadCharsFromTTY(int fd, int flags, char *buffer, int n)
|
||||
int ReadCharsFromTTY(int id, void *ctx, char *buffer, int n)
|
||||
{
|
||||
#pragma unused (id)
|
||||
long len = 0;
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
lshcontext *context = (lshcontext *)ctx;
|
||||
|
||||
if ( !context ) {
|
||||
return 0;
|
||||
|
@ -675,9 +683,10 @@ int ReadCharsFromTTY(int fd, int flags, char *buffer, int n)
|
|||
/*
|
||||
* AvailableFromTTY
|
||||
*/
|
||||
int AvailableFromTTY(int id, int flags)
|
||||
int AvailableFromTTY(int id, void *ctx)
|
||||
{
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
#pragma unused (id)
|
||||
lshcontext *context = (lshcontext *)ctx;
|
||||
|
||||
if ( !context ) {
|
||||
return 0;
|
||||
|
@ -1176,8 +1185,10 @@ void lsh_delete(lshctx *ctx)
|
|||
lshcontext *context = ctx->context;
|
||||
context->_gConsoleInEOF = true;
|
||||
pthread_kill( ctx->pthread, SIGINT );
|
||||
ctx->pthread = NULL;
|
||||
ssh2_sched();
|
||||
while (ctx->pthread) {
|
||||
/* wait for thread to die */
|
||||
ssh2_sched();
|
||||
}
|
||||
}
|
||||
if ( ctx->argstr != NULL ) {
|
||||
DisposePtr( ctx->argstr );
|
||||
|
|
|
@ -492,44 +492,44 @@ pascal Ptr PLstrrchr(ConstStr255Param s, short c)
|
|||
/*
|
||||
* InstallTTY
|
||||
*/
|
||||
int InstallTTY(int id, int flags)
|
||||
int InstallTTY(int id, void *context)
|
||||
{
|
||||
#pragma unused (id, flags)
|
||||
#pragma unused (id, context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* RemoveTTY
|
||||
*/
|
||||
void RemoveTTY(int id, int flags)
|
||||
void RemoveTTY(int id, void *context)
|
||||
{
|
||||
#pragma unused (id, flags)
|
||||
#pragma unused (id, context)
|
||||
}
|
||||
|
||||
/*
|
||||
* WriteCharsToTTY
|
||||
*/
|
||||
int WriteCharsToTTY(int id, int flags, char *buffer, int n)
|
||||
int WriteCharsToTTY(int id, void *context, char *buffer, int n)
|
||||
{
|
||||
#pragma unused (id, flags)
|
||||
#pragma unused (id, context)
|
||||
return WriteCharsToConsole(buffer, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* ReadCharsFromTTY
|
||||
*/
|
||||
int ReadCharsFromTTY(int id, int flags, char *buffer, int n)
|
||||
int ReadCharsFromTTY(int id, void *context, char *buffer, int n)
|
||||
{
|
||||
#pragma unused (id, flags)
|
||||
#pragma unused (id, context)
|
||||
return ReadCharsFromConsole(buffer, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* AvailableFromTTY
|
||||
*/
|
||||
int AvailableFromTTY(int id, int flags)
|
||||
int AvailableFromTTY(int id, void *context)
|
||||
{
|
||||
#pragma unused (id, flags)
|
||||
#pragma unused (id, context)
|
||||
extern short gSIOUXBufSize;
|
||||
if ( !gSIOUXBufSize ) {
|
||||
QHdrPtr eventQueue = LMGetEventQueue();
|
||||
|
|
|
@ -90,9 +90,9 @@ void ssh2_init()
|
|||
gethostid();
|
||||
|
||||
/*GUSISetupConsole();*/
|
||||
sGUSISetup = true;
|
||||
|
||||
g_error_fd = open("dev:ttyerr", O_WRONLY );
|
||||
|
||||
sGUSISetup = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
extern void syslog( int priority, const char *format, ...);
|
||||
|
||||
static void accept_call();
|
||||
static void check_listener();
|
||||
static void accept_call(lshcontext *context);
|
||||
static void check_listener(lshcontext *context);
|
||||
|
||||
|
||||
/*
|
||||
|
@ -191,13 +191,8 @@ void clrscr()
|
|||
* accept_call
|
||||
*/
|
||||
|
||||
static void accept_call()
|
||||
static void accept_call(lshcontext *context)
|
||||
{
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
|
||||
if ( !context ) {
|
||||
return;
|
||||
}
|
||||
if ( context->_listener != -1 && context->_socket == -1 ) {
|
||||
struct sockaddr peer;
|
||||
socklen_t addr_len = sizeof(peer);
|
||||
|
@ -230,13 +225,8 @@ static void accept_call()
|
|||
* check_listener
|
||||
*/
|
||||
|
||||
static void check_listener()
|
||||
static void check_listener(lshcontext *context)
|
||||
{
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
|
||||
if ( !context ) {
|
||||
return;
|
||||
}
|
||||
if ( context->_listener != -1 && context->_socket == -1 ) {
|
||||
struct fd_set rfds;
|
||||
struct timeval timeout;
|
||||
|
@ -246,7 +236,7 @@ static void check_listener()
|
|||
timeout.tv_usec = 0;
|
||||
if ( select( 32, &rfds, NULL, NULL, &timeout ) ) {
|
||||
if ( FD_ISSET( context->_listener, &rfds ) ) {
|
||||
accept_call();
|
||||
accept_call(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -292,43 +282,43 @@ static long read_local_socket(lshcontext *context, char *buffer, long n)
|
|||
/*
|
||||
* InstallTTY
|
||||
*/
|
||||
int InstallTTY(int fd, int flags)
|
||||
int InstallTTY(int id, void *ctx)
|
||||
{
|
||||
#pragma unused (fd)
|
||||
#pragma unused (id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* RemoveTTY
|
||||
*/
|
||||
void RemoveTTY(int fd, int flags)
|
||||
void RemoveTTY(int id, void *ctx)
|
||||
{
|
||||
#pragma unused (fd)
|
||||
#pragma unused (id)
|
||||
}
|
||||
|
||||
/*
|
||||
* WriteCharsToTTY
|
||||
*/
|
||||
int WriteCharsToTTY(int fd, int flags, char *buffer, int n)
|
||||
int WriteCharsToTTY(int id, void *ctx, char *buffer, int n)
|
||||
{
|
||||
long written = 0;
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
lshcontext *context = ctx;
|
||||
char *buf = buffer;
|
||||
char c;
|
||||
|
||||
if ( !context ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( fd == 2 ) {
|
||||
if ( id == 2 ) {
|
||||
// log stderr to console
|
||||
putlln( buffer, n );
|
||||
return n;
|
||||
}
|
||||
|
||||
if ( !context ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( context->_listener != -1 ) {
|
||||
/* write data to local socket */
|
||||
check_listener();
|
||||
check_listener(context);
|
||||
if ( context->_socket != -1 ) {
|
||||
while ( n > 0 && context->_socket != -1 ) {
|
||||
long len = n;
|
||||
|
@ -411,10 +401,10 @@ int WriteCharsToTTY(int fd, int flags, char *buffer, int n)
|
|||
/*
|
||||
* ReadCharsFromTTY
|
||||
*/
|
||||
int ReadCharsFromTTY(int fd, int flags, char *buffer, int n)
|
||||
int ReadCharsFromTTY(int id, void *ctx, char *buffer, int n)
|
||||
{
|
||||
long len = 0;
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
lshcontext *context = ctx;
|
||||
|
||||
if ( !context ) {
|
||||
return 0;
|
||||
|
@ -440,7 +430,7 @@ int ReadCharsFromTTY(int fd, int flags, char *buffer, int n)
|
|||
ssh2_sched();
|
||||
if ( context->_listener != -1 ) {
|
||||
/* read data from local socket */
|
||||
check_listener();
|
||||
check_listener(context);
|
||||
if ( context->_socket != -1 ) {
|
||||
len = read_local_socket(context, buffer, n);
|
||||
if ( context->_socket == -1 && len == 0 ) {
|
||||
|
@ -463,9 +453,9 @@ int ReadCharsFromTTY(int fd, int flags, char *buffer, int n)
|
|||
/*
|
||||
* AvailableFromTTY
|
||||
*/
|
||||
int AvailableFromTTY(int id, int flags)
|
||||
int AvailableFromTTY(int id, void *ctx)
|
||||
{
|
||||
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
|
||||
lshcontext *context = ctx;
|
||||
|
||||
if ( !context ) {
|
||||
return 0;
|
||||
|
@ -486,7 +476,7 @@ int AvailableFromTTY(int id, int flags)
|
|||
if ( select( 32, &rfds, NULL, &efds, &timeout ) ) {
|
||||
if ( context->_socket == -1 ) {
|
||||
if ( FD_ISSET( context->_listener, &rfds ) ) {
|
||||
accept_call();
|
||||
accept_call(context);
|
||||
}
|
||||
} else {
|
||||
if ( FD_ISSET( context->_socket, &efds ) ) {
|
||||
|
|
Loading…
Reference in New Issue