Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15527
Modified Files:
Tag: desiredata
m_pd.h s_inter.c m_sched.c s_main.c desire.tk s_stuff.h
x_net.c
Log Message:
new gui socket system using [netreceive]
Index: desire.tk
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.tk,v
retrieving revision 1.1.2.600.2.2
retrieving revision 1.1.2.600.2.3
diff -C2 -d -r1.1.2.600.2.2 -r1.1.2.600.2.3
*** desire.tk 1 Dec 2006 21:00:02 -0000 1.1.2.600.2.2
--- desire.tk 2 Dec 2006 03:12:12 -0000 1.1.2.600.2.3
***************
*** 717,720 ****
--- 717,721 ----
}
+ # this is becoming obsolete (2006.12.01)
proc accept_pd {s addr port} {
global sock
***************
*** 764,769 ****
}
set server_port 13666
! set server_sock [socket -server accept_pd $server_port]
if {$cmdline(valgrind)} {
--- 765,784 ----
}
+ proc pd_connect {} {
+ global sock
+ if {[catch {set sock [socket localhost 13666]}]} {
+ post "can't connect... wait a second"
+ after 1000 pd_connect
+ return
+ }
+ post "connected!"
+ fconfigure $sock -blocking 0 -buffering line
+ pd pd init
+ poll_sock
+ }
+
set server_port 13666
! #set server_sock [socket -server accept_pd $server_port]
! after 1000 pd_connect
if {$cmdline(valgrind)} {
Index: s_main.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_main.c,v
retrieving revision 1.7.4.17.2.22.2.7
retrieving revision 1.7.4.17.2.22.2.8
diff -C2 -d -r1.7.4.17.2.22.2.7 -r1.7.4.17.2.22.2.8
*** s_main.c 1 Dec 2006 19:27:19 -0000 1.7.4.17.2.22.2.7
--- s_main.c 2 Dec 2006 03:12:12 -0000 1.7.4.17.2.22.2.8
***************
*** 57,63 ****
int sys_verbose;
int sys_noloadbang;
- int sys_nogui;
int sys_hipriority = -1; /* -1 = don't care; 0 = no; 1 = yes */
! int sys_guisetportnumber; /* if started from the GUI, this is the port # */
char *sys_guicmd;
--- 57,62 ----
int sys_verbose;
int sys_noloadbang;
int sys_hipriority = -1; /* -1 = don't care; 0 = no; 1 = yes */
! int sys_guisetportnumber = 5400;
char *sys_guicmd;
***************
*** 131,135 ****
}
! /* for DesireData this should be eventually nuked */
void glob_initfromgui(void *dummy, t_symbol *s)
{
--- 130,138 ----
}
! extern t_text *sys_netreceive;
! extern t_socketreceiver *sys_socketreceiver;
! t_socketreceiver *netreceive_newest_receiver(t_text *x);
!
! /* this should be rethought for multi-client */
void glob_initfromgui(void *dummy, t_symbol *s)
{
***************
*** 137,140 ****
--- 140,146 ----
t_namelist *nl;
getcwd(cwd,665);
+ sys_socketreceiver=netreceive_newest_receiver(sys_netreceive);
+ fprintf(stderr,"sys_socketreceiver=%p\n",sys_socketreceiver);
+
/* load dynamic libraries specified with "-lib" args */
for (nl = sys_externlist; nl; nl = nl->nl_next)
***************
*** 347,353 ****
"-noloadbang -- suppress all loadbangs\n",
"-stderr -- send printout to standard error instead of GUI\n",
! "-nogui -- suppress starting the GUI\n",
! "-guiport <n> -- connect to pre-existing GUI over port <n>\n",
! "-guicmd \"cmd...\" -- start alternatve GUI program (e.g., remote via ssh)\n",
"-send \"msg...\" -- send a message at startup, after patches are loaded\n",
#ifdef UNISTD
--- 353,357 ----
"-noloadbang -- suppress all loadbangs\n",
"-stderr -- send printout to standard error instead of GUI\n",
! "-guiport <n> -- set port that the GUI should connect to\n",
"-send \"msg...\" -- send a message at startup, after patches are loaded\n",
#ifdef UNISTD
***************
*** 645,649 ****
}
if (ARG("-noloadbang",1)) {sys_noloadbang = 1; NEXT(1);}
! if (ARG("-nogui",1)) {sys_printtostderr = sys_nogui = 1; NEXT(1);}
if (ARG("-guiport",2)) {
if (sscanf(argv[1], "%d", &sys_guisetportnumber)<1) goto usage;
--- 649,657 ----
}
if (ARG("-noloadbang",1)) {sys_noloadbang = 1; NEXT(1);}
! if (ARG("-nogui",1)) {
! sys_printtostderr = 1;
! fprintf(stderr,"Warning: -nogui is obsolete: nowadays it does just like -stderr instead\n");
! NEXT(1);
! }
if (ARG("-guiport",2)) {
if (sscanf(argv[1], "%d", &sys_guisetportnumber)<1) goto usage;
***************
*** 651,655 ****
}
if (ARG("-stderr",1)) {sys_printtostderr = 1; NEXT(1);}
! if (ARG("-guicmd",2)) {sys_guicmd = argv[1]; NEXT(2);}
if (ARG("-send",2)) {
sys_messagelist = namelist_append(sys_messagelist, argv[1], 1);
--- 659,666 ----
}
if (ARG("-stderr",1)) {sys_printtostderr = 1; NEXT(1);}
! if (ARG("-guicmd",2)) {
! fprintf(stderr,"Warning: -guicmd ignored");
! NEXT(2);
! }
if (ARG("-send",2)) {
sys_messagelist = namelist_append(sys_messagelist, argv[1], 1);
Index: m_sched.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v
retrieving revision 1.5.4.35.2.21
retrieving revision 1.5.4.35.2.21.2.1
diff -C2 -d -r1.5.4.35.2.21 -r1.5.4.35.2.21.2.1
*** m_sched.c 23 Nov 2006 05:59:42 -0000 1.5.4.35.2.21
--- m_sched.c 2 Dec 2006 03:12:12 -0000 1.5.4.35.2.21.2.1
***************
*** 294,298 ****
where we arrange to ping the watchdog every 2 seconds. */
#ifdef __linux__
! if (sys_nogui && sys_hipriority && (sched_diddsp - sched_nextpingtime > 0))
{
glob_watchdog(0);
--- 294,298 ----
where we arrange to ping the watchdog every 2 seconds. */
#ifdef __linux__
! if (sys_hipriority && (sched_diddsp - sched_nextpingtime > 0))
{
glob_watchdog(0);
Index: s_stuff.h
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_stuff.h,v
retrieving revision 1.5.4.10.2.8
retrieving revision 1.5.4.10.2.8.2.1
diff -C2 -d -r1.5.4.10.2.8 -r1.5.4.10.2.8.2.1
*** s_stuff.h 25 Nov 2006 08:06:19 -0000 1.5.4.10.2.8
--- s_stuff.h 2 Dec 2006 03:12:13 -0000 1.5.4.10.2.8.2.1
***************
*** 167,181 ****
EXTERN void sys_microsleep(int microsec);
-
EXTERN void sys_bail(int exitcode);
EXTERN int sys_pollgui(void);
-
- EXTERN_STRUCT _socketreceiver;
- #define t_socketreceiver struct _socketreceiver
-
typedef void (*t_socketnotifier)(void *x);
typedef void (*t_socketreceivefn)(void *x, t_binbuf *b);
! EXTERN t_socketreceiver *socketreceiver_new(void *owner,
t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp);
EXTERN void socketreceiver_read(t_socketreceiver *x, int fd);
--- 167,190 ----
EXTERN void sys_microsleep(int microsec);
EXTERN void sys_bail(int exitcode);
EXTERN int sys_pollgui(void);
typedef void (*t_socketnotifier)(void *x);
typedef void (*t_socketreceivefn)(void *x, t_binbuf *b);
! typedef struct _socketreceiver {
! char *inbuf;
! int inhead;
! int intail;
! void *owner;
! int udp;
! t_socketnotifier notifier;
! t_socketreceivefn socketreceivefn;
! /* for sending only: */
! int fd;
! char *outbuf;
! struct _socketreceiver *next;
! } t_socketreceiver;
!
! EXTERN t_socketreceiver *socketreceiver_new(t_pd *owner, int fd,
t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp);
EXTERN void socketreceiver_read(t_socketreceiver *x, int fd);
Index: s_inter.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_inter.c,v
retrieving revision 1.5.4.10.2.25.2.3
retrieving revision 1.5.4.10.2.25.2.4
diff -C2 -d -r1.5.4.10.2.25.2.3 -r1.5.4.10.2.25.2.4
*** s_inter.c 1 Dec 2006 19:27:19 -0000 1.5.4.10.2.25.2.3
--- s_inter.c 2 Dec 2006 03:12:12 -0000 1.5.4.10.2.25.2.4
***************
*** 84,98 ****
#define INBUFSIZE 4096
- struct _socketreceiver
- {
- char *sr_inbuf;
- int sr_inhead;
- int sr_intail;
- void *sr_owner;
- int sr_udp;
- t_socketnotifier sr_notifier;
- t_socketreceivefn sr_socketreceivefn;
- };
-
extern char pd_version[];
extern int sys_guisetportnumber;
--- 84,87 ----
***************
*** 101,108 ****
static t_fdpoll *sys_fdpoll;
static int sys_maxfd;
! static int sys_guisock;
!
static t_binbuf *inbinbuf;
! static t_socketreceiver *sys_socketreceiver;
extern int sys_addhist(int phase);
--- 90,96 ----
static t_fdpoll *sys_fdpoll;
static int sys_maxfd;
! t_text *sys_netreceive;
static t_binbuf *inbinbuf;
! t_socketreceiver *sys_socketreceiver;
extern int sys_addhist(int phase);
***************
*** 429,466 ****
}
! t_socketreceiver *socketreceiver_new(void *owner, t_socketnotifier notifier,
t_socketreceivefn socketreceivefn, int udp)
{
t_socketreceiver *x = (t_socketreceiver *)getbytes(sizeof(*x));
! x->sr_inhead = x->sr_intail = 0;
! x->sr_owner = owner;
! x->sr_notifier = notifier;
! x->sr_socketreceivefn = socketreceivefn;
! x->sr_udp = udp;
! if (!(x->sr_inbuf = (char *)malloc(INBUFSIZE))) bug("t_socketreceiver");;
! return (x);
}
void socketreceiver_free(t_socketreceiver *x)
{
! free(x->sr_inbuf);
freebytes(x, sizeof(*x));
}
! /* this is in a separately called subroutine so that the buffer isn't
! sitting on the stack while the messages are getting passed. */
static int socketreceiver_doread(t_socketreceiver *x)
{
char messbuf[INBUFSIZE], *bp = messbuf;
int indx;
! int inhead = x->sr_inhead;
! int intail = x->sr_intail;
! char *inbuf = x->sr_inbuf;
! if (intail == inhead) return (0);
for (indx = intail; indx != inhead; indx = (indx+1)&(INBUFSIZE-1))
{
! /* if we hit a semi that isn't preceeded by a \, it's a message
! boundary. LATER we should deal with the possibility that the
! preceeding \ might itself be escaped! */
char c = *bp++ = inbuf[indx];
if (c == ';' && (!indx || inbuf[indx-1] != '\\'))
--- 417,457 ----
}
! t_socketreceiver *socketreceiver_new(t_pd *owner, int fd, t_socketnotifier notifier,
t_socketreceivefn socketreceivefn, int udp)
{
t_socketreceiver *x = (t_socketreceiver *)getbytes(sizeof(*x));
! x->inhead = x->intail = 0;
! x->owner = owner;
! x->notifier = notifier;
! x->socketreceivefn = socketreceivefn;
! x->udp = udp;
! x->fd = fd;
! x->outbuf = 0;
! x->next = 0;
! if (!(x->inbuf = (char *)malloc(INBUFSIZE))) bug("t_socketreceiver");;
! return x;
}
void socketreceiver_free(t_socketreceiver *x)
{
! free(x->inbuf);
freebytes(x, sizeof(*x));
}
! /* this is in a separately called subroutine so that the buffer isn't
! sitting on the stack while the messages are getting passed. */
static int socketreceiver_doread(t_socketreceiver *x)
{
char messbuf[INBUFSIZE], *bp = messbuf;
int indx;
! int inhead = x->inhead;
! int intail = x->intail;
! char *inbuf = x->inbuf;
! if (intail == inhead) return 0;
for (indx = intail; indx != inhead; indx = (indx+1)&(INBUFSIZE-1))
{
! /* if we hit a semi that isn't preceeded by a \, it's a message
! boundary. LATER we should deal with the possibility that the
! preceding \ might itself be escaped! */
char c = *bp++ = inbuf[indx];
if (c == ';' && (!indx || inbuf[indx-1] != '\\'))
***************
*** 473,478 ****
write(2, "\n", 1);
}
! x->sr_inhead = inhead;
! x->sr_intail = intail;
return (1);
}
--- 464,469 ----
write(2, "\n", 1);
}
! x->inhead = inhead;
! x->intail = intail;
return (1);
}
***************
*** 511,517 ****
binbuf_text(inbinbuf, buf, strlen(buf));
outlet_setstacklim();
! if (x->sr_socketreceivefn)
! (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
! else bug("socketreceiver_getudp");
}
}
--- 502,506 ----
binbuf_text(inbinbuf, buf, strlen(buf));
outlet_setstacklim();
! x->socketreceivefn(x->owner, inbinbuf);
}
}
***************
*** 520,589 ****
void sys_exit(void);
! void binbuf_eval_from_client(t_binbuf *b);
!
! void socketreceiver_read(t_socketreceiver *x, int fd)
! {
! if (x->sr_udp) /* UDP ("datagram") socket protocol */
! socketreceiver_getudp(x, fd);
! else /* TCP ("streaming") socket protocol */
! {
! char *semi;
! int readto =
! (x->sr_inhead >= x->sr_intail ? INBUFSIZE : x->sr_intail-1);
! int ret;
!
! /* the input buffer might be full. If so, drop the whole thing */
! if (readto == x->sr_inhead)
! {
! fprintf(stderr, "pd: dropped message from gui\n");
! x->sr_inhead = x->sr_intail = 0;
! readto = INBUFSIZE;
! }
! else
! {
! ret = recv(fd, x->sr_inbuf + x->sr_inhead,
! readto - x->sr_inhead, 0);
! if (ret < 0)
! {
! sys_sockerror("recv");
! if (x == sys_socketreceiver) sys_bail(1);
! else
! {
! if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
! sys_rmpollfn(fd);
! sys_closesocket(fd);
! }
! }
! else if (ret == 0)
! {
! if (x == sys_socketreceiver)
! {
! fprintf(stderr, "pd: exiting\n");
! sys_exit();
! return;
! }
! else
! {
! post("EOF on socket %d\n", fd);
! if (x->sr_notifier) (*x->sr_notifier)(x->sr_owner);
! sys_rmpollfn(fd);
! sys_closesocket(fd);
! }
! }
! else
! {
! x->sr_inhead += ret;
! if (x->sr_inhead >= INBUFSIZE) x->sr_inhead = 0;
! while (socketreceiver_doread(x))
! {
! outlet_setstacklim();
! if (x->sr_socketreceivefn)
! (*x->sr_socketreceivefn)(x->sr_owner, inbinbuf);
! else {
! binbuf_eval_from_client(inbinbuf);
! }
! }
! }
! }
}
}
--- 509,537 ----
void sys_exit(void);
! void socketreceiver_read(t_socketreceiver *x, int fd) {
! int readto;
! if (x->udp) {socketreceiver_getudp(x, fd); return;}
! /* else TCP */
! readto = x->inhead >= x->intail ? INBUFSIZE : x->intail-1;
! /* the input buffer might be full. If so, drop the whole thing */
! if (readto == x->inhead) {
! fprintf(stderr, "pd: dropped message from gui\n");
! x->inhead = x->intail = 0;
! readto = INBUFSIZE;
! } else {
! int ret = recv(fd, x->inbuf+x->inhead, readto-x->inhead, 0);
! if (ret<=0) {
! if (ret<0) sys_sockerror("recv"); else post("EOF on socket %d\n", fd);
! if (x->notifier) x->notifier(x->owner);
! sys_rmpollfn(fd);
! sys_closesocket(fd);
! return;
! }
! x->inhead += ret;
! if (x->inhead >= INBUFSIZE) x->inhead = 0;
! while (socketreceiver_doread(x)) {
! outlet_setstacklim();
! x->socketreceivefn(x->owner, inbinbuf);
! }
}
}
***************
*** 604,616 ****
#define GUI_BYTESPERPING 1024 /* how much we send up per ping */
- typedef struct _guiqueue
- {
- void *gq_client;
- t_glist *gq_glist;
- t_guicallbackfn gq_fn;
- struct _guiqueue *gq_next;
- } t_guiqueue;
-
- static t_guiqueue *sys_guiqueuehead;
static char *sys_guibuf;
static int sys_guibufhead;
--- 552,555 ----
***************
*** 620,687 ****
static int sys_bytessincelastping;
! static void sys_trytogetmoreguibuf(int newsize)
! {
char *newbuf = (char *)realloc(sys_guibuf, newsize);
! #if 0
! static int sizewas;
! if (newsize > 70000 && sizewas < 70000)
! {
! int i;
! for (i = sys_guibuftail; i < sys_guibufhead; i++)
! fputc(sys_guibuf[i], stderr);
! }
! sizewas = newsize;
! #endif
! #if 0
! fprintf(stderr, "new size %d (head %d, tail %d)\n",
! newsize, sys_guibufhead, sys_guibuftail);
! #endif
!
! /* if realloc fails, make a last-ditch attempt to stay alive by
! synchronously writing out the existing contents. LATER test
! this by intentionally setting newbuf to zero */
! if (!newbuf)
! {
! int bytestowrite = sys_guibuftail - sys_guibufhead;
! int written = 0;
! while (1)
! {
! int res = send(sys_guisock,
! sys_guibuf + sys_guibuftail + written, bytestowrite, 0);
! if (res < 0)
! {
! perror("pd output pipe");
! sys_bail(1);
! }
! else
! {
! written += res;
! if (written >= bytestowrite)
! break;
! }
! }
! sys_guibufhead = sys_guibuftail = 0;
! }
! else
! {
! sys_guibufsize = newsize;
! sys_guibuf = newbuf;
! }
}
! void sys_vgui(char *fmt, ...)
! {
! int msglen, bytesleft, headwas, nwrote;
va_list ap;
!
! if (sys_nogui)
! return;
! if (!sys_guibuf)
! {
! if (!(sys_guibuf = (char *)malloc(GUI_ALLOCCHUNK)))
! {
! fprintf(stderr, "Pd: couldn't allocate GUI buffer\n");
! sys_bail(1);
! }
sys_guibufsize = GUI_ALLOCCHUNK;
sys_guibufhead = sys_guibuftail = 0;
--- 559,574 ----
static int sys_bytessincelastping;
! static void sys_trytogetmoreguibuf(int newsize) {
char *newbuf = (char *)realloc(sys_guibuf, newsize);
! sys_guibufsize = newsize;
! sys_guibuf = newbuf;
}
! void sys_vgui(char *fmt, ...) {
! // t_socketreceiver *self = sys_socketreceiver;
! int msglen;
va_list ap;
! if (!sys_guibuf) {
! sys_guibuf = (char *)malloc(GUI_ALLOCCHUNK);
sys_guibufsize = GUI_ALLOCCHUNK;
sys_guibufhead = sys_guibuftail = 0;
***************
*** 690,877 ****
sys_trytogetmoreguibuf(sys_guibufsize + GUI_ALLOCCHUNK);
va_start(ap, fmt);
! msglen = vsnprintf(sys_guibuf + sys_guibufhead,
! sys_guibufsize - sys_guibufhead, fmt, ap);
va_end(ap);
! if(msglen < 0)
! {
fprintf(stderr, "Pd: buffer space wasn't sufficient for long GUI string\n");
return;
}
! if (msglen >= sys_guibufsize - sys_guibufhead)
! {
! int msglen2, newsize = sys_guibufsize + 1 +
! (msglen > GUI_ALLOCCHUNK ? msglen : GUI_ALLOCCHUNK);
sys_trytogetmoreguibuf(newsize);
-
va_start(ap, fmt);
msglen2 = vsnprintf(sys_guibuf + sys_guibufhead,
sys_guibufsize - sys_guibufhead, fmt, ap);
va_end(ap);
! if (msglen2 != msglen)
! bug("sys_vgui");
! if (msglen >= sys_guibufsize - sys_guibufhead)
! msglen = sys_guibufsize - sys_guibufhead;
}
! if (sys_debuglevel & DEBUG_MESSUP)
! fprintf(stderr, "%s", sys_guibuf + sys_guibufhead);
sys_guibufhead += msglen;
sys_bytessincelastping += msglen;
}
! void sys_gui(char *s)
! {
! sys_vgui("%s", s);
! }
! static int sys_flushtogui( void)
! {
int writesize = sys_guibufhead - sys_guibuftail, nwrote = 0;
! if (writesize > 0)
! nwrote = send(sys_guisock, sys_guibuf + sys_guibuftail, writesize, 0);
!
! #if 0
! if (writesize)
! fprintf(stderr, "wrote %d of %d\n", nwrote, writesize);
! #endif
!
! if (nwrote < 0)
! {
perror("pd-to-gui socket");
sys_bail(1);
! }
! else if (!nwrote)
! return (0);
! else if (nwrote >= sys_guibufhead - sys_guibuftail)
sys_guibufhead = sys_guibuftail = 0;
! else if (nwrote)
! {
sys_guibuftail += nwrote;
! if (sys_guibuftail > (sys_guibufsize >> 2))
! {
! memmove(sys_guibuf, sys_guibuf + sys_guibuftail,
! sys_guibufhead - sys_guibuftail);
sys_guibufhead = sys_guibufhead - sys_guibuftail;
sys_guibuftail = 0;
}
}
! return (1);
! }
!
! void glob_ping(t_pd *dummy)
! {
! sys_waitingforping = 0;
! }
!
! static int sys_flushqueue(void )
! {
! int wherestop = sys_bytessincelastping + GUI_UPDATESLICE;
! if (wherestop + (GUI_UPDATESLICE >> 1) > GUI_BYTESPERPING)
! wherestop = 0x7fffffff;
! if (sys_waitingforping)
! return (0);
! if (!sys_guiqueuehead)
! return (0);
! while (1)
! {
! if (sys_bytessincelastping >= GUI_BYTESPERPING)
! {
! sys_gui("pdtk_ping\n");
! sys_bytessincelastping = 0;
! sys_waitingforping = 1;
! return (1);
! }
! if (sys_guiqueuehead)
! {
! t_guiqueue *headwas = sys_guiqueuehead;
! sys_guiqueuehead = headwas->gq_next;
! (*headwas->gq_fn)((t_gobj *)headwas->gq_client, headwas->gq_glist);
! t_freebytes(headwas, sizeof(*headwas));
! if (sys_bytessincelastping >= wherestop)
! break;
! }
! else break;
! }
! sys_flushtogui();
! return (1);
! }
!
! /* flush output buffer and update queue to gui in small time slices */
! static int sys_poll_togui(void) /* returns 1 if did anything */
! {
! if (sys_nogui)
! return (0);
! /* see if there is stuff still in the buffer, if so we
! must have fallen behind, so just try to clear that. */
! if (sys_flushtogui())
! return (1);
! /* if the flush wasn't complete, wait. */
! if (sys_guibufhead > sys_guibuftail)
! return (0);
!
! /* check for queued updates */
! if (sys_flushqueue())
! return (1);
!
! return (0);
! }
!
! /* if some GUI object is having to do heavy computations, it can tell
! us to back off from doing more updates by faking a big one itself. */
! void sys_pretendguibytes(int n)
! {
! sys_bytessincelastping += n;
! }
!
! void sys_queuegui(void *client, t_glist *glist, t_guicallbackfn f)
! {
! t_guiqueue **gqnextptr, *gq;
! if (!sys_guiqueuehead)
! gqnextptr = &sys_guiqueuehead;
! else
! {
! for (gq = sys_guiqueuehead; gq->gq_next; gq = gq->gq_next)
! if (gq->gq_client == client)
! return;
! gqnextptr = &gq->gq_next;
! }
! gq = (t_guiqueue *)t_getbytes(sizeof(*gq));
! gq->gq_next = 0;
! gq->gq_client = client;
! gq->gq_glist = glist;
! gq->gq_fn = f;
! gq->gq_next = 0;
! *gqnextptr = gq;
}
! void sys_unqueuegui(void *client)
! {
! t_guiqueue *gq, *gq2;
! if (!sys_guiqueuehead)
! return;
! if (sys_guiqueuehead->gq_client == client)
! {
! t_freebytes(sys_guiqueuehead, sizeof(*sys_guiqueuehead));
! sys_guiqueuehead = 0;
! }
! else for (gq = sys_guiqueuehead; gq2 = gq->gq_next; gq = gq2)
! if (gq2->gq_client == client)
! {
! gq->gq_next = gq2->gq_next;
! t_freebytes(gq2, sizeof(*gq2));
! break;
! }
! }
! int sys_pollgui(void)
! {
! return (sys_pollsockets() || sys_poll_togui());
}
-
-
/* --------------------- starting up the GUI connection ------------- */
- static int sys_watchfd;
-
#ifdef __linux__
void glob_watchdog(t_pd *dummy)
--- 577,635 ----
sys_trytogetmoreguibuf(sys_guibufsize + GUI_ALLOCCHUNK);
va_start(ap, fmt);
! msglen = vsnprintf(sys_guibuf + sys_guibufhead, sys_guibufsize - sys_guibufhead, fmt, ap);
va_end(ap);
! if(msglen < 0) {
fprintf(stderr, "Pd: buffer space wasn't sufficient for long GUI string\n");
return;
}
! if (msglen >= sys_guibufsize - sys_guibufhead) {
! int msglen2, newsize = sys_guibufsize + 1 + (msglen > GUI_ALLOCCHUNK ? msglen : GUI_ALLOCCHUNK);
sys_trytogetmoreguibuf(newsize);
va_start(ap, fmt);
msglen2 = vsnprintf(sys_guibuf + sys_guibufhead,
sys_guibufsize - sys_guibufhead, fmt, ap);
va_end(ap);
! if (msglen2 != msglen) bug("sys_vgui");
! if (msglen >= sys_guibufsize - sys_guibufhead) msglen = sys_guibufsize - sys_guibufhead;
}
! if (sys_debuglevel & DEBUG_MESSUP) fprintf(stderr, "%s", sys_guibuf + sys_guibufhead);
sys_guibufhead += msglen;
sys_bytessincelastping += msglen;
}
! void sys_gui(char *s) {sys_vgui("%s", s);}
! static int sys_flushtogui(t_socketreceiver *self) {
int writesize = sys_guibufhead - sys_guibuftail, nwrote = 0;
! if (!writesize) return 0;
! fprintf(stderr,"sys_flushtogui self=%p writesize=%d\n",self,writesize);
! nwrote = send(self->fd, sys_guibuf + sys_guibuftail, writesize, 0);
! if (nwrote < 0) {
perror("pd-to-gui socket");
sys_bail(1);
! } else if (!nwrote) {
! return 0;
! } else if (nwrote >= sys_guibufhead - sys_guibuftail) {
sys_guibufhead = sys_guibuftail = 0;
! } else if (nwrote) {
sys_guibuftail += nwrote;
! if (sys_guibuftail > (sys_guibufsize >> 2)) {
! memmove(sys_guibuf, sys_guibuf + sys_guibuftail, sys_guibufhead - sys_guibuftail);
sys_guibufhead = sys_guibufhead - sys_guibuftail;
sys_guibuftail = 0;
}
}
! return 1;
}
! void glob_ping(t_pd *dummy) {sys_waitingforping = 0;}
! int sys_pollgui(void) {
! if (sys_socketreceiver) sys_flushtogui(sys_socketreceiver);
! return sys_pollsockets();
}
/* --------------------- starting up the GUI connection ------------- */
#ifdef __linux__
void glob_watchdog(t_pd *dummy)
***************
*** 887,934 ****
#endif
! #define FIRSTPORTNUM 5400
!
! static int sys_start_watchdog_thread(void);
!
! static t_int fake_initfromgui(t_int* dummy)
! {
! char cmdbuf[4*MAXPDSTRING];
! int i;
! #ifdef MSW
! if (GetCurrentDirectory(MAXPDSTRING, cmdbuf) == 0)
! strcpy(cmdbuf, ".");
! #endif
! #ifdef UNISTD
! if (!getcwd(cmdbuf, MAXPDSTRING))
! strcpy(cmdbuf, ".");
!
! #endif
! glob_initfromgui(0,0);
! return 0;
! }
!
! void sys_setpriority(void);
!
! int sys_startgui(void)
! {
! pid_t childpid;
! char cmdbuf[4*MAXPDSTRING];
! struct sockaddr_in server;
! int msgsock;
! char buf[15];
! int len = sizeof(server);
! int ntry = 0, portno = FIRSTPORTNUM;
! int xsock = -1;
! #ifdef _WIN32
! short version = MAKEWORD(2, 0);
! WSADATA nobby;
! #endif /* _WIN32 */
! #ifdef UNISTD
! int stdinpipe[2];
! #endif
! /* create an empty FD poll list */
! sys_fdpoll = (t_fdpoll *)t_getbytes(0);
! sys_nfdpoll = 0;
! inbinbuf = binbuf_new();
#ifdef UNISTD
signal(SIGHUP, sys_huphandler);
--- 645,649 ----
#endif
! static void sys_setsignals(void) {
#ifdef UNISTD
signal(SIGHUP, sys_huphandler);
***************
*** 945,980 ****
/* GG says: don't set SIGSTKFLT */
#endif
#ifdef _WIN32
if (WSAStartup(version, &nobby)) sys_sockerror("WSAstartup");
#endif /* _WIN32 */
! if (sys_nogui) {
! sys_callback((t_int(*)(t_int*))fake_initfromgui,0,0);
! } else if (sys_guisetportnumber) { /* GUI exists and sent us a port number */
! struct sockaddr_in server;
! struct hostent *hp;
! /* create a socket */
! sys_guisock = socket(AF_INET, SOCK_STREAM, 0);
! if (sys_guisock < 0) sys_sockerror("socket");
! /* connect socket using hostname provided in command line */
! server.sin_family = AF_INET;
! hp = gethostbyname(LOCALHOST);
! if (hp == 0) {
! fprintf(stderr, "localhost not found (inet protocol not installed?)\n");
! exit(1);
! }
! memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
! /* assign client port number */
! server.sin_port = htons((unsigned short)sys_guisetportnumber);
! /* try to connect */
! if (connect(sys_guisock, (struct sockaddr *) &server, sizeof (server)) < 0) {
! sys_sockerror("connecting stream socket");
! exit(1);
! }
! } else {
! fprintf(stderr,
! "PureData in DesireData mode does not currently support starting without\n"
! "a -guiport option. Please start using the command 'wish desire.tk' instead.\n");
! exit(1);
! }
#if defined(__linux__) || defined(IRIX)
--- 660,695 ----
/* GG says: don't set SIGSTKFLT */
#endif
+ }
+
+ //t_pd *pd_new3(const char *s);
+
+ void *netreceive_new(t_symbol *compatflag, t_floatarg fportno, t_floatarg udpflag);
+ static int sys_start_watchdog_thread(void);
+ static void sys_setpriority(void);
+ extern t_text *manager;
+
+ int sys_startgui(void) {
+ t_text *printer0;
+ t_text *printer1;
#ifdef _WIN32
+ short version = MAKEWORD(2, 0);
+ WSADATA nobby;
if (WSAStartup(version, &nobby)) sys_sockerror("WSAstartup");
#endif /* _WIN32 */
! /* create an empty FD poll list */
! sys_fdpoll = (t_fdpoll *)t_getbytes(0);
! sys_nfdpoll = 0;
! inbinbuf = binbuf_new();
! sys_setsignals();
!
! fprintf(stderr,"sys_guisetportnumber=%d\n",sys_guisetportnumber);
! sys_netreceive = netreceive_new(&s_,sys_guisetportnumber,0);
! fprintf(stderr,"sys_netreceive=%p\n",sys_netreceive);
! if (!sys_netreceive) return;
! printer0 = (t_text *)pd_new3("print left");
! printer1 = (t_text *)pd_new3("print right");
! obj_connect(sys_netreceive,0,printer0,0);
! obj_connect(sys_netreceive,1,printer1,0);
! obj_connect(sys_netreceive,0,manager,0);
#if defined(__linux__) || defined(IRIX)
***************
*** 988,999 ****
if (sys_hipriority) sys_setpriority();
setuid(getuid());
! if (!sys_nogui) {
char buf[256], buf2[256];
- sys_socketreceiver = socketreceiver_new(0,0,0,0);
- sys_addpollfn(sys_guisock, (t_fdpollfn)socketreceiver_read, sys_socketreceiver);
sys_get_audio_apis(buf);
sys_get_midi_apis(buf2);
sys_vgui("pdtk_pd_startup {%s} %s %s\n", pd_version, buf, buf2);
! }
return 0;
}
--- 703,712 ----
if (sys_hipriority) sys_setpriority();
setuid(getuid());
! /*
char buf[256], buf2[256];
sys_get_audio_apis(buf);
sys_get_midi_apis(buf2);
sys_vgui("pdtk_pd_startup {%s} %s %s\n", pd_version, buf, buf2);
! */
return 0;
}
***************
*** 1062,1076 ****
#endif /* __APPLE__ */
- #if 0
- if (!sys_nogui && !sys_guisetportnumber) {
- if (sys_verbose) fprintf(stderr, "Waiting for connection request... \n");
- if (listen(xsock, 5) < 0) sys_sockerror("listen");
- sys_guisock = accept(xsock, (struct sockaddr *) &server, (socklen_t *)&len);
- close(xsock); //OOPS
- if (sys_guisock < 0) sys_sockerror("accept");
- if (sys_verbose) fprintf(stderr, "... connected\n");
- }
- #endif
-
if (!sys_nogui)
{
--- 775,778 ----
***************
*** 1106,1119 ****
void glob_closeall(void *dummy, t_floatarg fforce);
! void glob_quit(void *dummy)
! {
glob_closeall(0, 1);
! sys_vgui("exit\n");
! if (!sys_nogui)
! {
! close(sys_guisock);
! sys_rmpollfn(sys_guisock);
! }
! sys_bail(0);
}
--- 808,814 ----
void glob_closeall(void *dummy, t_floatarg fforce);
! void glob_quit(void *dummy) {
glob_closeall(0, 1);
! sys_bail(0);
}
Index: m_pd.h
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v
retrieving revision 1.4.4.11.2.33.2.1
retrieving revision 1.4.4.11.2.33.2.2
diff -C2 -d -r1.4.4.11.2.33.2.1 -r1.4.4.11.2.33.2.2
*** m_pd.h 30 Nov 2006 03:30:36 -0000 1.4.4.11.2.33.2.1
--- m_pd.h 2 Dec 2006 03:12:12 -0000 1.4.4.11.2.33.2.2
***************
*** 459,464 ****
char *result,int resultsize);
EXTERN t_symbol *canvas_getdir(t_glist *x);
- EXTERN int sys_fontwidth(int fontsize);
- EXTERN int sys_fontheight(int fontsize);
EXTERN void canvas_dataproperties(t_glist *x, t_scalar *sc, t_binbuf *b);
--- 459,462 ----
***************
*** 817,827 ****
/* ------- GUI interface - functions to send strings to TK --------- */
- typedef void (*t_guicallbackfn)(t_gobj *client, t_glist *glist);
-
EXTERN void sys_vgui(char *fmt, ...);
EXTERN void sys_gui(char *s);
- EXTERN void sys_pretendguibytes(int n);
- EXTERN void sys_queuegui(void *client, t_glist *glist, t_guicallbackfn f);
- EXTERN void sys_unqueuegui(void *client);
/* dialog window creation and destruction */
EXTERN void gfxstub_new(t_pd *owner, void *key, const char *cmd);
--- 815,820 ----
***************
*** 878,879 ****
--- 871,877 ----
#define __m_pd_h_
#endif /* __m_pd_h_ */
+
+ /* removed features:
+ sys_fontwidth, sys_fontheight, t_widgetbehavior, class_setproperties, class_setwidget,
+ sys_pretendguibytes, sys_queuegui, sys_unqueuegui
+ */
Index: x_net.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/x_net.c,v
retrieving revision 1.2.4.2.2.2
retrieving revision 1.2.4.2.2.2.2.1
diff -C2 -d -r1.2.4.2.2.2 -r1.2.4.2.2.2.2.1
*** x_net.c 30 Nov 2005 13:36:58 -0000 1.2.4.2.2.2
--- x_net.c 2 Dec 2006 03:12:13 -0000 1.2.4.2.2.2.2.1
***************
*** 192,195 ****
--- 192,197 ----
int x_nconnections;
int x_udp;
+ /* only used for sending */
+ t_socketreceiver *sr;
} t_netreceive;
***************
*** 201,208 ****
static void netreceive_doit(void *z, t_binbuf *b)
{
- t_atom messbuf[1024];
t_netreceive *x = (t_netreceive *)z;
int msg, natom = binbuf_getnatom(b);
t_atom *at = binbuf_getvec(b);
for (msg = 0; msg < natom;)
{
--- 203,210 ----
static void netreceive_doit(void *z, t_binbuf *b)
{
t_netreceive *x = (t_netreceive *)z;
int msg, natom = binbuf_getnatom(b);
t_atom *at = binbuf_getvec(b);
+ fprintf(stderr,"%s\n",__PRETTY_FUNCTION__);
for (msg = 0; msg < natom;)
{
***************
*** 241,254 ****
else
{
! t_socketreceiver *y = socketreceiver_new((void *)x,
! (t_socketnotifier)netreceive_notify,
! (x->x_msgout ? netreceive_doit : 0), 0);
sys_addpollfn(fd, (t_fdpollfn)socketreceiver_read, y);
outlet_float(x->x_connectout, ++x->x_nconnections);
}
}
! static void *netreceive_new(t_symbol *compatflag,
! t_floatarg fportno, t_floatarg udpflag)
{
t_netreceive *x;
--- 243,257 ----
else
{
! t_socketreceiver *y = socketreceiver_new((t_pd *)x, fd,
! (t_socketnotifier)netreceive_notify, x->x_msgout?netreceive_doit:0, 0);
sys_addpollfn(fd, (t_fdpollfn)socketreceiver_read, y);
outlet_float(x->x_connectout, ++x->x_nconnections);
+ y->next = x->sr;
+ x->sr = y;
}
}
! void *netreceive_new(t_symbol *compatflag,
! t_floatarg fportno, t_floatarg udpflag)
{
t_netreceive *x;
***************
*** 271,275 ****
#if 1
! /* ask OS to allow another Pd to repoen this port after we close it. */
intarg = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
--- 274,278 ----
#if 1
! /* ask OS to allow another Pd to reopen this port after we close it. */
intarg = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
***************
*** 312,316 ****
{
t_socketreceiver *y = socketreceiver_new((void *)x,
! (t_socketnotifier)netreceive_notify,
(x->x_msgout ? netreceive_doit : 0), 1);
sys_addpollfn(sockfd, (t_fdpollfn)socketreceiver_read, y);
--- 315,319 ----
{
t_socketreceiver *y = socketreceiver_new((void *)x,
! (t_socketnotifier)netreceive_notify, sockfd,
(x->x_msgout ? netreceive_doit : 0), 1);
sys_addpollfn(sockfd, (t_fdpollfn)socketreceiver_read, y);
***************
*** 334,338 ****
x->x_nconnections = 0;
x->x_udp = udp;
!
return (x);
}
--- 337,341 ----
x->x_nconnections = 0;
x->x_udp = udp;
! x->sr = 0;
return (x);
}
***************
*** 362,363 ****
--- 365,369 ----
}
+ t_socketreceiver *netreceive_newest_receiver(t_netreceive *x) {
+ return x->sr;
+ }
\ No newline at end of file