some plugin bug fixes, and implementing client sockets in cfactor
parent
a0b66d2028
commit
73a4e3e6c5
|
@ -1,6 +1,5 @@
|
|||
- sidekick: error source not removed
|
||||
- lineno/file for native
|
||||
- jedit for native with socket communication
|
||||
- native client socket
|
||||
- input style after clicking link
|
||||
- fedit broken with listener
|
||||
- maple-like: press enter at old commands to evaluate there
|
||||
|
@ -9,6 +8,7 @@
|
|||
- enforce bottom-up in native bootstrap
|
||||
- standalone listener input style
|
||||
- add a socket timeout
|
||||
- drop test in http server
|
||||
|
||||
+ docs:
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
|||
- sbuf-hashcode
|
||||
- vector-hashcode
|
||||
- review doc formatting with latex2html
|
||||
- recursion -vs- iteration in vectors chapter
|
||||
|
||||
+ tests:
|
||||
|
||||
|
@ -28,7 +29,8 @@
|
|||
|
||||
+ listener/plugin:
|
||||
|
||||
- words with < in name
|
||||
- jedit bug? +line doesn't always work when switching into an existing
|
||||
buffer with a remembered first line
|
||||
- auto insert USE:
|
||||
- why > 1 popup
|
||||
- listener backspace overzealous
|
||||
|
|
|
@ -145,6 +145,8 @@ public class FactorSideKickParser extends SideKickParser
|
|||
|
||||
parsed = parsed.next();
|
||||
}
|
||||
|
||||
last.end = buffer.createPosition(buffer.getLength());
|
||||
} //}}}
|
||||
|
||||
//{{{ supportsCompletion() method
|
||||
|
@ -267,5 +269,5 @@ public class FactorSideKickParser extends SideKickParser
|
|||
{
|
||||
Log.log(Log.ERROR,this,e);
|
||||
}
|
||||
}
|
||||
} //}}}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ package factor.jedit;
|
|||
import factor.*;
|
||||
import java.awt.Component;
|
||||
import javax.swing.*;
|
||||
import org.gjt.sp.jedit.jEdit;
|
||||
import org.gjt.sp.jedit.*;
|
||||
|
||||
public class FactorWordRenderer extends DefaultListCellRenderer
|
||||
{
|
||||
|
@ -80,8 +80,12 @@ public class FactorWordRenderer extends DefaultListCellRenderer
|
|||
}
|
||||
|
||||
setText(jEdit.getProperty(prop,
|
||||
new String[] { word.name,
|
||||
stackEffect }));
|
||||
new String[] {
|
||||
MiscUtilities.charsToEntities(word.name),
|
||||
stackEffect == null
|
||||
? 0 :
|
||||
MiscUtilities.charsToEntities(stackEffect)
|
||||
}));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ public class FactorListener extends JTextPane
|
|||
private Cons readLineContinuation;
|
||||
private int cmdStart = -1;
|
||||
|
||||
private SimpleAttributeSet nullAttributes = new SimpleAttributeSet();
|
||||
private SimpleAttributeSet nullAttributes;
|
||||
|
||||
//{{{ FactorListener constructor
|
||||
public FactorListener()
|
||||
{
|
||||
|
@ -66,6 +67,8 @@ public class FactorListener extends JTextPane
|
|||
|
||||
listenerList = new EventListenerList();
|
||||
|
||||
nullAttributes = new SimpleAttributeSet();
|
||||
|
||||
/* Replace enter to evaluate the input */
|
||||
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),
|
||||
new EnterAction());
|
||||
|
|
|
@ -62,6 +62,7 @@ DEFER: clone-sbuf
|
|||
IN: io-internals
|
||||
DEFER: port?
|
||||
DEFER: open-file
|
||||
DEFER: client-socket
|
||||
DEFER: server-socket
|
||||
DEFER: close-fd
|
||||
DEFER: add-accept-io-task
|
||||
|
@ -210,6 +211,7 @@ IN: cross-compiler
|
|||
set-callstack
|
||||
port?
|
||||
exit*
|
||||
client-socket
|
||||
server-socket
|
||||
close-fd
|
||||
add-accept-io-task
|
||||
|
|
|
@ -88,6 +88,8 @@ primitives,
|
|||
"/library/httpd/test-responder.factor"
|
||||
"/library/httpd/quit-responder.factor"
|
||||
"/library/httpd/default-responders.factor"
|
||||
"/library/jedit/jedit-remote.factor"
|
||||
"/library/jedit/jedit.factor"
|
||||
"/library/math/arc-trig-hyp.factor"
|
||||
"/library/math/arithmetic.factor"
|
||||
"/library/math/list-math.factor"
|
||||
|
|
|
@ -87,6 +87,9 @@ USE: unparser
|
|||
: <client-stream> ( host port in out -- stream )
|
||||
<fd-stream> [ ":" swap unparse cat3 "client" set ] extend ;
|
||||
|
||||
: <client> ( host port -- stream )
|
||||
2dup client-socket <client-stream> ;
|
||||
|
||||
: accept ( server -- client )
|
||||
#! Accept a connection from a server socket.
|
||||
"socket" swap get* blocking-accept <client-stream> ;
|
||||
|
|
|
@ -59,3 +59,14 @@ void range_error(CELL tagged, CELL index, CELL max)
|
|||
tag_cons(cons(tag_fixnum(max),F)))));
|
||||
general_error(ERROR_RANGE,tag_cons(c));
|
||||
}
|
||||
|
||||
void io_error(const char* func)
|
||||
{
|
||||
STRING* function = from_c_string(func);
|
||||
STRING* error = from_c_string(strerror(errno));
|
||||
|
||||
CONS* c = cons(tag_object(function),tag_cons(
|
||||
cons(tag_object(error),F)));
|
||||
|
||||
general_error(ERROR_IO,tag_cons(c));
|
||||
}
|
||||
|
|
|
@ -16,3 +16,4 @@ void throw_error(CELL object);
|
|||
void general_error(CELL error, CELL tagged);
|
||||
void type_error(CELL type, CELL tagged);
|
||||
void range_error(CELL tagged, CELL index, CELL max);
|
||||
void io_error(const char* func);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#define INLINE inline static
|
||||
|
||||
|
|
21
native/fd.c
21
native/fd.c
|
@ -33,7 +33,7 @@ bool read_step(PORT* port)
|
|||
if(amount == -1)
|
||||
{
|
||||
if(errno != EAGAIN)
|
||||
io_error(port,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
@ -103,7 +103,7 @@ void primitive_read_line_fd_8(void)
|
|||
port->line_ready = false;
|
||||
}
|
||||
else
|
||||
io_error(port,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ bool write_step(PORT* port)
|
|||
if(amount == -1)
|
||||
{
|
||||
if(errno != EAGAIN)
|
||||
io_error(port,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
@ -165,7 +165,7 @@ void write_fd_char_8(PORT* port, FIXNUM ch)
|
|||
char c = (char)ch;
|
||||
|
||||
if(!can_write(port,1))
|
||||
io_error(port,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
bput((CELL)port->buffer + sizeof(STRING) + port->buf_fill,c);
|
||||
port->buf_fill++;
|
||||
|
@ -177,7 +177,7 @@ void write_fd_string_8(PORT* port, STRING* str)
|
|||
|
||||
/* Note this ensures the buffer is large enough to fit the string */
|
||||
if(!can_write(port,str->capacity))
|
||||
io_error(port,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
c_str = to_c_string(str);
|
||||
|
||||
|
@ -216,14 +216,3 @@ void primitive_close_fd(void)
|
|||
PORT* port = untag_port(dpop());
|
||||
close(port->fd);
|
||||
}
|
||||
|
||||
void io_error(PORT* port, const char* func)
|
||||
{
|
||||
STRING* function = from_c_string(func);
|
||||
STRING* error = from_c_string(strerror(errno));
|
||||
|
||||
CONS* c = cons(tag_object(function),tag_cons(
|
||||
cons(tag_object(error),F)));
|
||||
|
||||
general_error(ERROR_IO,tag_cons(c));
|
||||
}
|
||||
|
|
|
@ -16,4 +16,4 @@ void write_fd_char_8(PORT* port, FIXNUM ch);
|
|||
void write_fd_string_8(PORT* port, STRING* str);
|
||||
void primitive_write_fd_8(void);
|
||||
void primitive_close_fd(void);
|
||||
void io_error(PORT* port, const char* func);
|
||||
void io_error(const char* func);
|
||||
|
|
|
@ -19,7 +19,7 @@ void primitive_open_file(void)
|
|||
|
||||
fd = open(path,mode,FILE_MODE);
|
||||
if(fd < 0)
|
||||
io_error(NULL,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
dpush(read ? tag_object(port(PORT_READ,fd)) : F);
|
||||
dpush(write ? tag_object(port(PORT_WRITE,fd)) : F);
|
||||
|
|
|
@ -32,7 +32,7 @@ PORT* port(PORT_MODE type, CELL fd)
|
|||
port->buffer = string(BUF_SIZE,'\0');
|
||||
|
||||
if(fcntl(port->fd,F_SETFL,O_NONBLOCK,1) == -1)
|
||||
io_error(port,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ XT primitives[] = {
|
|||
primitive_set_callstack,
|
||||
primitive_portp,
|
||||
primitive_exit,
|
||||
primitive_client_socket,
|
||||
primitive_server_socket,
|
||||
primitive_close_fd,
|
||||
primitive_add_accept_io_task,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
extern XT primitives[];
|
||||
#define PRIMITIVE_COUNT 133
|
||||
#define PRIMITIVE_COUNT 134
|
||||
|
||||
CELL primitive_to_xt(CELL primitive);
|
||||
|
|
|
@ -1,6 +1,52 @@
|
|||
#include "factor.h"
|
||||
|
||||
int make_server_socket(CHAR port)
|
||||
void init_sockaddr(struct sockaddr_in* name,
|
||||
const char* hostname, uint16_t port)
|
||||
{
|
||||
struct hostent *hostinfo;
|
||||
|
||||
name->sin_family = AF_INET;
|
||||
name->sin_port = htons(port);
|
||||
hostinfo = gethostbyname(hostname);
|
||||
|
||||
if(hostinfo == NULL)
|
||||
io_error(__FUNCTION__);
|
||||
}
|
||||
|
||||
int make_client_socket(const char* hostname, uint16_t port)
|
||||
{
|
||||
int sock;
|
||||
struct sockaddr_in servername;
|
||||
|
||||
/* Create the socket. */
|
||||
sock = socket(PF_INET,SOCK_STREAM,0);
|
||||
if(sock < 0)
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
if(fcntl(sock,F_SETFL,O_NONBLOCK,1) == -1)
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
/* Connect to the server. */
|
||||
init_sockaddr(&servername,hostname,port);
|
||||
if(connect(sock,(struct sockaddr *)&servername,sizeof(servername)) < 0)
|
||||
{
|
||||
if(errno != EINPROGRESS)
|
||||
io_error(__FUNCTION__);
|
||||
}
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
void primitive_client_socket(void)
|
||||
{
|
||||
uint16_t p = (uint16_t)to_fixnum(dpop());
|
||||
char* host = to_c_string(untag_string(dpop()));
|
||||
int sock = make_client_socket(host,p);
|
||||
dpush(tag_object(port(PORT_READ,sock)));
|
||||
dpush(tag_object(port(PORT_WRITE,sock)));
|
||||
}
|
||||
|
||||
int make_server_socket(uint16_t port)
|
||||
{
|
||||
int sock;
|
||||
struct sockaddr_in name;
|
||||
|
@ -11,11 +57,11 @@ int make_server_socket(CHAR port)
|
|||
sock = socket(PF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if(sock < 0)
|
||||
io_error(NULL,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
/* Reuse port number */
|
||||
if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&reuseaddr,sizeof(int)) < 0)
|
||||
io_error(NULL,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
|
||||
/* Give the socket a name */
|
||||
name.sin_family = AF_INET;
|
||||
|
@ -24,14 +70,14 @@ int make_server_socket(CHAR port)
|
|||
if(bind(sock,(struct sockaddr *)&name, sizeof(name)) < 0)
|
||||
{
|
||||
close(sock);
|
||||
io_error(NULL,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
}
|
||||
|
||||
/* Start listening for connections */
|
||||
if(listen(sock,1) < 0)
|
||||
{
|
||||
close(sock);
|
||||
io_error(NULL,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
}
|
||||
|
||||
return sock;
|
||||
|
@ -39,7 +85,7 @@ int make_server_socket(CHAR port)
|
|||
|
||||
void primitive_server_socket(void)
|
||||
{
|
||||
CHAR p = (CHAR)to_fixnum(dpop());
|
||||
uint16_t p = (uint16_t)to_fixnum(dpop());
|
||||
dpush(tag_object(port(PORT_SPECIAL,make_server_socket(p))));
|
||||
}
|
||||
|
||||
|
@ -56,11 +102,11 @@ CELL accept_connection(PORT* p)
|
|||
if(errno == EAGAIN)
|
||||
return false;
|
||||
else
|
||||
io_error(NULL,__FUNCTION__);
|
||||
io_error(__FUNCTION__);
|
||||
}
|
||||
|
||||
/* if(setsockopt(new,SOL_SOCKET,SO_OOBINLINE,&oobinline,sizeof(int)) < 0)
|
||||
io_error(NULL,__FUNCTION__); */
|
||||
io_error(__FUNCTION__); */
|
||||
|
||||
p->client_host = tag_object(from_c_string(inet_ntoa(
|
||||
clientname.sin_addr)));
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
int make_server_socket(CHAR port);
|
||||
void init_sockaddr(struct sockaddr_in *name,
|
||||
const char *hostname, uint16_t port);
|
||||
int make_client_socket(const char* hostname, uint16_t port);
|
||||
void primitive_client_socket(void);
|
||||
int make_server_socket(uint16_t port);
|
||||
void primitive_server_socket(void);
|
||||
CELL accept_connection(PORT* p);
|
||||
void primitive_accept_fd(void);
|
||||
|
|
Loading…
Reference in New Issue