It should work.
This commit is contained in:
parent
028bc33645
commit
66a07a3b72
151
lib/sockstuff.c
151
lib/sockstuff.c
@ -27,7 +27,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/lib/sockstuff.c,v 1.1 2005/06/26 04:47:20 dcp1990 Exp $ */
|
/* $Amigan: phoned/lib/sockstuff.c,v 1.2 2005/06/26 15:51:22 dcp1990 Exp $ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -46,39 +46,31 @@
|
|||||||
#include <tcl.h>
|
#include <tcl.h>
|
||||||
|
|
||||||
#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
|
#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
|
||||||
|
typedef struct cdta {
|
||||||
|
int fd;
|
||||||
|
Tcl_Channel channel;
|
||||||
|
} Udom_Cdata_t;
|
||||||
|
|
||||||
int UdomConnectSocket (cdata, interp, argc, argv)
|
|
||||||
|
int Udom_Close(cdata, interp)
|
||||||
ClientData cdata;
|
ClientData cdata;
|
||||||
Tcl_Interp *interp;
|
Tcl_Interp *interp;
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
{
|
{
|
||||||
int s;
|
int rc;
|
||||||
struct sockaddr_un them;
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
if(argc < 2) {
|
rc = close(idata->fd);
|
||||||
return TCL_ERROR;
|
ckfree((char*)idata);
|
||||||
}
|
return rc == 0 ? rc : errno;
|
||||||
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
||||||
strcpy(them.sun_path, sockfile);
|
|
||||||
them.sun_family = AF_LOCAL;
|
|
||||||
if(connect(s, (struct sockaddr *)&them, 1 + strlen(them.sun_path) + sizeof(them.sun_family)) == -1) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int UdomClose(idata, interp)
|
int Udom_Input(cdata, buf, sizebuf, errorptr)
|
||||||
ClientData idata;
|
ClientData cdata;
|
||||||
Tcl_Interp *interp;
|
|
||||||
{
|
|
||||||
close(socket);
|
|
||||||
}
|
|
||||||
int UdomInput(idata, buf, sizebuf, errorptr)
|
|
||||||
ClientData idata;
|
|
||||||
char *buf;
|
char *buf;
|
||||||
int sizebuf;
|
int sizebuf;
|
||||||
int *errorptr;
|
int *errorptr;
|
||||||
{
|
{
|
||||||
int ec;
|
int ec;
|
||||||
ec = read((int)idata, buf, sizebuf);
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
ec = read(idata->fd, buf, sizebuf);
|
||||||
if(ec == -1) {
|
if(ec == -1) {
|
||||||
*errorptr = errno;
|
*errorptr = errno;
|
||||||
return -1;
|
return -1;
|
||||||
@ -87,14 +79,15 @@ int UdomInput(idata, buf, sizebuf, errorptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UdomOutput(idata, buf, towrite, ecptr)
|
int Udom_Output(cdata, buf, towrite, ecptr)
|
||||||
ClientData idata;
|
ClientData cdata;
|
||||||
CONST char *buf;
|
CONST char *buf;
|
||||||
int towrite;
|
int towrite;
|
||||||
int *ecptr;
|
int *ecptr;
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
rc = write((int)idata, buf, towrite);
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
rc = write(idata->fd, buf, towrite);
|
||||||
if(rc == -1) {
|
if(rc == -1) {
|
||||||
*ecptr = errno;
|
*ecptr = errno;
|
||||||
return -1;
|
return -1;
|
||||||
@ -103,21 +96,107 @@ int UdomOutput(idata, buf, towrite, ecptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Udom_Watch(cdata, mask)
|
||||||
|
ClientData cdata;
|
||||||
|
int mask;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
if(mask) {
|
||||||
|
Tcl_CreateFileHandler(idata->fd, mask,
|
||||||
|
(Tcl_FileProc*)Tcl_NotifyChannel,
|
||||||
|
(ClientData)idata->channel);
|
||||||
|
} else {
|
||||||
|
Tcl_DeleteFileHandler(idata->fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Udom_GetHandle(cdata, dir, handptr)
|
||||||
|
ClientData cdata;
|
||||||
|
int dir;
|
||||||
|
ClientData *handptr;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
*handptr = (ClientData)idata->fd;
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* write watcher */
|
/* write watcher */
|
||||||
Tcl_ChannelType ourchan = {
|
Tcl_ChannelType Udom_ChanType = {
|
||||||
"udomain",
|
"udomain",
|
||||||
TCL_CHANNEL_VERSION_3,
|
TCL_CHANNEL_VERSION_3,
|
||||||
&UdomClose,
|
&Udom_Close,
|
||||||
&UdomInput,
|
&Udom_Input,
|
||||||
&UdomOutput,
|
&Udom_Output,
|
||||||
NULL, /* seek */
|
NULL, /* seek */
|
||||||
NULL, /* set and getoption, might do later */
|
NULL, /* set and getoption, might do later */
|
||||||
NULL,
|
NULL,
|
||||||
&UdomWatch,
|
&Udom_Watch,
|
||||||
&UdomGetHandle,
|
&Udom_GetHandle,
|
||||||
NULL, /* close2proc */
|
NULL, /* close2proc */
|
||||||
NULL, /* block mode */
|
NULL, /* block mode */
|
||||||
&UdomFlush,
|
NULL, /* flush */
|
||||||
&UdomHandler,
|
NULL, /* handler */
|
||||||
&UdomWideSeek /* return EINVAL */
|
NULL /* wideseek */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Tcl_Channel Udom_CreateChannel(sockfile, mask)
|
||||||
|
CONST char *sockfile;
|
||||||
|
int mask;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *cdt;
|
||||||
|
int s;
|
||||||
|
char chname[25];
|
||||||
|
struct sockaddr_un them;
|
||||||
|
cdt = (Udom_Cdata_t*)ckalloc(sizeof(Udom_Cdata_t));
|
||||||
|
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||||
|
strcpy(them.sun_path, sockfile);
|
||||||
|
them.sun_family = AF_LOCAL;
|
||||||
|
if(connect(s, (struct sockaddr *)&them, 1 + strlen(them.sun_path) + sizeof(them.sun_family)) == -1) {
|
||||||
|
ckfree((char*)cdt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
cdt->fd = s;
|
||||||
|
snprintf(chname, 24, "udom%d", cdt->fd);
|
||||||
|
cdt->channel = Tcl_CreateChannel(&Udom_ChanType, chname, cdt, mask);
|
||||||
|
return cdt->channel;
|
||||||
|
}
|
||||||
|
int Udom_MakeSock (cdata, interp, argc, argv)
|
||||||
|
ClientData cdata;
|
||||||
|
Tcl_Interp *interp;
|
||||||
|
int argc;
|
||||||
|
Tcl_Obj *const argv[];
|
||||||
|
{
|
||||||
|
char *arg;
|
||||||
|
char *sfl = NULL;
|
||||||
|
int a, optind;
|
||||||
|
Tcl_Channel res;
|
||||||
|
const char *udomopt[] = {
|
||||||
|
"-file", (char*)NULL
|
||||||
|
};
|
||||||
|
enum udomopt {
|
||||||
|
UDOM_FILE
|
||||||
|
};
|
||||||
|
for(a = 1; a < argc; a++) {
|
||||||
|
arg = Tcl_GetString(argv[a]);
|
||||||
|
if(*arg != '-') break;
|
||||||
|
if(Tcl_GetIndexFromObj(interp, argv[a], udomopt, "option", TCL_EXACT, &optind)
|
||||||
|
!= TCL_OK) return TCL_ERROR;
|
||||||
|
switch((enum udomopt)optind) {
|
||||||
|
case UDOM_FILE:
|
||||||
|
if(a >= argc) return qseterr("needs file!");
|
||||||
|
sfl = Tcl_GetString(argv[a]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Tcl_Panic("udom: bad optind to opts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(sfl == NULL) return qseterr("file argument REQUIRED.");
|
||||||
|
res = Udom_CreateChannel(sfl, TCL_READABLE | TCL_WRITABLE);
|
||||||
|
if(res == NULL) return TCL_ERROR;
|
||||||
|
Tcl_ResetResult(interp);
|
||||||
|
Tcl_AppendResult(interp, Tcl_GetChannelName(res), (char*)NULL);
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/lib/tcl/sockstuff.c,v 1.1 2005/06/26 04:47:20 dcp1990 Exp $ */
|
/* $Amigan: phoned/lib/tcl/sockstuff.c,v 1.2 2005/06/26 15:51:22 dcp1990 Exp $ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -46,39 +46,31 @@
|
|||||||
#include <tcl.h>
|
#include <tcl.h>
|
||||||
|
|
||||||
#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
|
#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
|
||||||
|
typedef struct cdta {
|
||||||
|
int fd;
|
||||||
|
Tcl_Channel channel;
|
||||||
|
} Udom_Cdata_t;
|
||||||
|
|
||||||
int UdomConnectSocket (cdata, interp, argc, argv)
|
|
||||||
|
int Udom_Close(cdata, interp)
|
||||||
ClientData cdata;
|
ClientData cdata;
|
||||||
Tcl_Interp *interp;
|
Tcl_Interp *interp;
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
{
|
{
|
||||||
int s;
|
int rc;
|
||||||
struct sockaddr_un them;
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
if(argc < 2) {
|
rc = close(idata->fd);
|
||||||
return TCL_ERROR;
|
ckfree((char*)idata);
|
||||||
}
|
return rc == 0 ? rc : errno;
|
||||||
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
||||||
strcpy(them.sun_path, sockfile);
|
|
||||||
them.sun_family = AF_LOCAL;
|
|
||||||
if(connect(s, (struct sockaddr *)&them, 1 + strlen(them.sun_path) + sizeof(them.sun_family)) == -1) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int UdomClose(idata, interp)
|
int Udom_Input(cdata, buf, sizebuf, errorptr)
|
||||||
ClientData idata;
|
ClientData cdata;
|
||||||
Tcl_Interp *interp;
|
|
||||||
{
|
|
||||||
close(socket);
|
|
||||||
}
|
|
||||||
int UdomInput(idata, buf, sizebuf, errorptr)
|
|
||||||
ClientData idata;
|
|
||||||
char *buf;
|
char *buf;
|
||||||
int sizebuf;
|
int sizebuf;
|
||||||
int *errorptr;
|
int *errorptr;
|
||||||
{
|
{
|
||||||
int ec;
|
int ec;
|
||||||
ec = read((int)idata, buf, sizebuf);
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
ec = read(idata->fd, buf, sizebuf);
|
||||||
if(ec == -1) {
|
if(ec == -1) {
|
||||||
*errorptr = errno;
|
*errorptr = errno;
|
||||||
return -1;
|
return -1;
|
||||||
@ -87,14 +79,15 @@ int UdomInput(idata, buf, sizebuf, errorptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UdomOutput(idata, buf, towrite, ecptr)
|
int Udom_Output(cdata, buf, towrite, ecptr)
|
||||||
ClientData idata;
|
ClientData cdata;
|
||||||
CONST char *buf;
|
CONST char *buf;
|
||||||
int towrite;
|
int towrite;
|
||||||
int *ecptr;
|
int *ecptr;
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
rc = write((int)idata, buf, towrite);
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
rc = write(idata->fd, buf, towrite);
|
||||||
if(rc == -1) {
|
if(rc == -1) {
|
||||||
*ecptr = errno;
|
*ecptr = errno;
|
||||||
return -1;
|
return -1;
|
||||||
@ -103,21 +96,107 @@ int UdomOutput(idata, buf, towrite, ecptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Udom_Watch(cdata, mask)
|
||||||
|
ClientData cdata;
|
||||||
|
int mask;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
if(mask) {
|
||||||
|
Tcl_CreateFileHandler(idata->fd, mask,
|
||||||
|
(Tcl_FileProc*)Tcl_NotifyChannel,
|
||||||
|
(ClientData)idata->channel);
|
||||||
|
} else {
|
||||||
|
Tcl_DeleteFileHandler(idata->fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Udom_GetHandle(cdata, dir, handptr)
|
||||||
|
ClientData cdata;
|
||||||
|
int dir;
|
||||||
|
ClientData *handptr;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
*handptr = (ClientData)idata->fd;
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* write watcher */
|
/* write watcher */
|
||||||
Tcl_ChannelType ourchan = {
|
Tcl_ChannelType Udom_ChanType = {
|
||||||
"udomain",
|
"udomain",
|
||||||
TCL_CHANNEL_VERSION_3,
|
TCL_CHANNEL_VERSION_3,
|
||||||
&UdomClose,
|
&Udom_Close,
|
||||||
&UdomInput,
|
&Udom_Input,
|
||||||
&UdomOutput,
|
&Udom_Output,
|
||||||
NULL, /* seek */
|
NULL, /* seek */
|
||||||
NULL, /* set and getoption, might do later */
|
NULL, /* set and getoption, might do later */
|
||||||
NULL,
|
NULL,
|
||||||
&UdomWatch,
|
&Udom_Watch,
|
||||||
&UdomGetHandle,
|
&Udom_GetHandle,
|
||||||
NULL, /* close2proc */
|
NULL, /* close2proc */
|
||||||
NULL, /* block mode */
|
NULL, /* block mode */
|
||||||
&UdomFlush,
|
NULL, /* flush */
|
||||||
&UdomHandler,
|
NULL, /* handler */
|
||||||
&UdomWideSeek /* return EINVAL */
|
NULL /* wideseek */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Tcl_Channel Udom_CreateChannel(sockfile, mask)
|
||||||
|
CONST char *sockfile;
|
||||||
|
int mask;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *cdt;
|
||||||
|
int s;
|
||||||
|
char chname[25];
|
||||||
|
struct sockaddr_un them;
|
||||||
|
cdt = (Udom_Cdata_t*)ckalloc(sizeof(Udom_Cdata_t));
|
||||||
|
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||||
|
strcpy(them.sun_path, sockfile);
|
||||||
|
them.sun_family = AF_LOCAL;
|
||||||
|
if(connect(s, (struct sockaddr *)&them, 1 + strlen(them.sun_path) + sizeof(them.sun_family)) == -1) {
|
||||||
|
ckfree((char*)cdt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
cdt->fd = s;
|
||||||
|
snprintf(chname, 24, "udom%d", cdt->fd);
|
||||||
|
cdt->channel = Tcl_CreateChannel(&Udom_ChanType, chname, cdt, mask);
|
||||||
|
return cdt->channel;
|
||||||
|
}
|
||||||
|
int Udom_MakeSock (cdata, interp, argc, argv)
|
||||||
|
ClientData cdata;
|
||||||
|
Tcl_Interp *interp;
|
||||||
|
int argc;
|
||||||
|
Tcl_Obj *const argv[];
|
||||||
|
{
|
||||||
|
char *arg;
|
||||||
|
char *sfl = NULL;
|
||||||
|
int a, optind;
|
||||||
|
Tcl_Channel res;
|
||||||
|
const char *udomopt[] = {
|
||||||
|
"-file", (char*)NULL
|
||||||
|
};
|
||||||
|
enum udomopt {
|
||||||
|
UDOM_FILE
|
||||||
|
};
|
||||||
|
for(a = 1; a < argc; a++) {
|
||||||
|
arg = Tcl_GetString(argv[a]);
|
||||||
|
if(*arg != '-') break;
|
||||||
|
if(Tcl_GetIndexFromObj(interp, argv[a], udomopt, "option", TCL_EXACT, &optind)
|
||||||
|
!= TCL_OK) return TCL_ERROR;
|
||||||
|
switch((enum udomopt)optind) {
|
||||||
|
case UDOM_FILE:
|
||||||
|
if(a >= argc) return qseterr("needs file!");
|
||||||
|
sfl = Tcl_GetString(argv[a]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Tcl_Panic("udom: bad optind to opts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(sfl == NULL) return qseterr("file argument REQUIRED.");
|
||||||
|
res = Udom_CreateChannel(sfl, TCL_READABLE | TCL_WRITABLE);
|
||||||
|
if(res == NULL) return TCL_ERROR;
|
||||||
|
Tcl_ResetResult(interp);
|
||||||
|
Tcl_AppendResult(interp, Tcl_GetChannelName(res), (char*)NULL);
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
16
xfone/Makefile
Normal file
16
xfone/Makefile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# xfone Makefile
|
||||||
|
# (C)2005, Dan Ponte
|
||||||
|
# $Amigan: phoned/xfone/Makefile,v 1.1 2005/06/26 15:51:22 dcp1990 Exp $
|
||||||
|
include ../global.mk
|
||||||
|
# basic stuff. we append for a reason.
|
||||||
|
CPPFLAGS+=-I/usr/local/include/tcl8.4
|
||||||
|
CFLAGS+=-g ${CPPFLAGS}
|
||||||
|
LDFLAGS+=-shared
|
||||||
|
# keep these up to date.
|
||||||
|
MAINBIN=udom.so
|
||||||
|
SRCS=sockstuff.c
|
||||||
|
OBJS=sockstuff.o
|
||||||
|
|
||||||
|
include ../main.mk
|
||||||
|
ourclean:
|
||||||
|
|
@ -27,7 +27,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/xfone/sockstuff.c,v 1.1 2005/06/26 04:47:20 dcp1990 Exp $ */
|
/* $Amigan: phoned/xfone/sockstuff.c,v 1.2 2005/06/26 15:51:22 dcp1990 Exp $ */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -46,39 +46,31 @@
|
|||||||
#include <tcl.h>
|
#include <tcl.h>
|
||||||
|
|
||||||
#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
|
#define CMD_ARGS (ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj *CONST objv[])
|
||||||
|
typedef struct cdta {
|
||||||
|
int fd;
|
||||||
|
Tcl_Channel channel;
|
||||||
|
} Udom_Cdata_t;
|
||||||
|
|
||||||
int UdomConnectSocket (cdata, interp, argc, argv)
|
|
||||||
|
int Udom_Close(cdata, interp)
|
||||||
ClientData cdata;
|
ClientData cdata;
|
||||||
Tcl_Interp *interp;
|
Tcl_Interp *interp;
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
{
|
{
|
||||||
int s;
|
int rc;
|
||||||
struct sockaddr_un them;
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
if(argc < 2) {
|
rc = close(idata->fd);
|
||||||
return TCL_ERROR;
|
ckfree((char*)idata);
|
||||||
}
|
return rc == 0 ? rc : errno;
|
||||||
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
||||||
strcpy(them.sun_path, sockfile);
|
|
||||||
them.sun_family = AF_LOCAL;
|
|
||||||
if(connect(s, (struct sockaddr *)&them, 1 + strlen(them.sun_path) + sizeof(them.sun_family)) == -1) {
|
|
||||||
return TCL_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int UdomClose(idata, interp)
|
int Udom_Input(cdata, buf, sizebuf, errorptr)
|
||||||
ClientData idata;
|
ClientData cdata;
|
||||||
Tcl_Interp *interp;
|
|
||||||
{
|
|
||||||
close(socket);
|
|
||||||
}
|
|
||||||
int UdomInput(idata, buf, sizebuf, errorptr)
|
|
||||||
ClientData idata;
|
|
||||||
char *buf;
|
char *buf;
|
||||||
int sizebuf;
|
int sizebuf;
|
||||||
int *errorptr;
|
int *errorptr;
|
||||||
{
|
{
|
||||||
int ec;
|
int ec;
|
||||||
ec = read((int)idata, buf, sizebuf);
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
ec = read(idata->fd, buf, sizebuf);
|
||||||
if(ec == -1) {
|
if(ec == -1) {
|
||||||
*errorptr = errno;
|
*errorptr = errno;
|
||||||
return -1;
|
return -1;
|
||||||
@ -87,14 +79,15 @@ int UdomInput(idata, buf, sizebuf, errorptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UdomOutput(idata, buf, towrite, ecptr)
|
int Udom_Output(cdata, buf, towrite, ecptr)
|
||||||
ClientData idata;
|
ClientData cdata;
|
||||||
CONST char *buf;
|
CONST char *buf;
|
||||||
int towrite;
|
int towrite;
|
||||||
int *ecptr;
|
int *ecptr;
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
rc = write((int)idata, buf, towrite);
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
rc = write(idata->fd, buf, towrite);
|
||||||
if(rc == -1) {
|
if(rc == -1) {
|
||||||
*ecptr = errno;
|
*ecptr = errno;
|
||||||
return -1;
|
return -1;
|
||||||
@ -103,21 +96,107 @@ int UdomOutput(idata, buf, towrite, ecptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Udom_Watch(cdata, mask)
|
||||||
|
ClientData cdata;
|
||||||
|
int mask;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
if(mask) {
|
||||||
|
Tcl_CreateFileHandler(idata->fd, mask,
|
||||||
|
(Tcl_FileProc*)Tcl_NotifyChannel,
|
||||||
|
(ClientData)idata->channel);
|
||||||
|
} else {
|
||||||
|
Tcl_DeleteFileHandler(idata->fd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int Udom_GetHandle(cdata, dir, handptr)
|
||||||
|
ClientData cdata;
|
||||||
|
int dir;
|
||||||
|
ClientData *handptr;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *idata = (Udom_Cdata_t*)cdata;
|
||||||
|
*handptr = (ClientData)idata->fd;
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* write watcher */
|
/* write watcher */
|
||||||
Tcl_ChannelType ourchan = {
|
Tcl_ChannelType Udom_ChanType = {
|
||||||
"udomain",
|
"udomain",
|
||||||
TCL_CHANNEL_VERSION_3,
|
TCL_CHANNEL_VERSION_3,
|
||||||
&UdomClose,
|
&Udom_Close,
|
||||||
&UdomInput,
|
&Udom_Input,
|
||||||
&UdomOutput,
|
&Udom_Output,
|
||||||
NULL, /* seek */
|
NULL, /* seek */
|
||||||
NULL, /* set and getoption, might do later */
|
NULL, /* set and getoption, might do later */
|
||||||
NULL,
|
NULL,
|
||||||
&UdomWatch,
|
&Udom_Watch,
|
||||||
&UdomGetHandle,
|
&Udom_GetHandle,
|
||||||
NULL, /* close2proc */
|
NULL, /* close2proc */
|
||||||
NULL, /* block mode */
|
NULL, /* block mode */
|
||||||
&UdomFlush,
|
NULL, /* flush */
|
||||||
&UdomHandler,
|
NULL, /* handler */
|
||||||
&UdomWideSeek /* return EINVAL */
|
NULL /* wideseek */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Tcl_Channel Udom_CreateChannel(sockfile, mask)
|
||||||
|
CONST char *sockfile;
|
||||||
|
int mask;
|
||||||
|
{
|
||||||
|
Udom_Cdata_t *cdt;
|
||||||
|
int s;
|
||||||
|
char chname[25];
|
||||||
|
struct sockaddr_un them;
|
||||||
|
cdt = (Udom_Cdata_t*)ckalloc(sizeof(Udom_Cdata_t));
|
||||||
|
s = socket(AF_LOCAL, SOCK_STREAM, 0);
|
||||||
|
strcpy(them.sun_path, sockfile);
|
||||||
|
them.sun_family = AF_LOCAL;
|
||||||
|
if(connect(s, (struct sockaddr *)&them, 1 + strlen(them.sun_path) + sizeof(them.sun_family)) == -1) {
|
||||||
|
ckfree((char*)cdt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
cdt->fd = s;
|
||||||
|
snprintf(chname, 24, "udom%d", cdt->fd);
|
||||||
|
cdt->channel = Tcl_CreateChannel(&Udom_ChanType, chname, cdt, mask);
|
||||||
|
return cdt->channel;
|
||||||
|
}
|
||||||
|
int Udom_MakeSock (cdata, interp, argc, argv)
|
||||||
|
ClientData cdata;
|
||||||
|
Tcl_Interp *interp;
|
||||||
|
int argc;
|
||||||
|
Tcl_Obj *const argv[];
|
||||||
|
{
|
||||||
|
char *arg;
|
||||||
|
char *sfl = NULL;
|
||||||
|
int a, optind;
|
||||||
|
Tcl_Channel res;
|
||||||
|
const char *udomopt[] = {
|
||||||
|
"-file", (char*)NULL
|
||||||
|
};
|
||||||
|
enum udomopt {
|
||||||
|
UDOM_FILE
|
||||||
|
};
|
||||||
|
for(a = 1; a < argc; a++) {
|
||||||
|
arg = Tcl_GetString(argv[a]);
|
||||||
|
if(*arg != '-') break;
|
||||||
|
if(Tcl_GetIndexFromObj(interp, argv[a], udomopt, "option", TCL_EXACT, &optind)
|
||||||
|
!= TCL_OK) return TCL_ERROR;
|
||||||
|
switch((enum udomopt)optind) {
|
||||||
|
case UDOM_FILE:
|
||||||
|
if(a >= argc) return qseterr("needs file!");
|
||||||
|
sfl = Tcl_GetString(argv[a]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Tcl_Panic("udom: bad optind to opts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(sfl == NULL) return qseterr("file argument REQUIRED.");
|
||||||
|
res = Udom_CreateChannel(sfl, TCL_READABLE | TCL_WRITABLE);
|
||||||
|
if(res == NULL) return TCL_ERROR;
|
||||||
|
Tcl_ResetResult(interp);
|
||||||
|
Tcl_AppendResult(interp, Tcl_GetChannelName(res), (char*)NULL);
|
||||||
|
return TCL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user