Enlightenment CVS committal
Author : raster
Project : e17
Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore_con
Modified Files:
Tag: SPLIT
ecore_con.c ecore_con_private.h
Log Message:
thar be tcp/ip support in ecore_con now... you can connect to any machine to
any port.. anywhere or advertise a service on any port... and get clients
connecting... :) it works! only 1 things that really pisses me off.. the
blocking gethostbyname(). i don't like that one little bit. i might want to
add client count limits for services and disconnect error codes in disconnect
events etc. but that doesnt bother me like the blocking gethostbyname()
===================================================================
RCS file: /cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_con/Attic/ecore_con.c,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -3 -r1.1.2.4 -r1.1.2.5
--- ecore_con.c 13 Mar 2003 06:12:50 -0000 1.1.2.4
+++ ecore_con.c 17 Mar 2003 07:33:57 -0000 1.1.2.5
@@ -12,6 +12,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
+#include <netdb.h>
static void _ecore_con_server_free(Ecore_Con_Server *svr);
static void _ecore_con_client_free(Ecore_Con_Client *cl);
@@ -89,6 +90,7 @@
const void *data)
{
Ecore_Con_Server *svr;
+ struct sockaddr_in socket_addr;
struct sockaddr_un socket_unix;
struct linger lin;
char buf[4096];
@@ -142,6 +144,26 @@
NULL, NULL);
if (!svr->fd_handler) goto error;
}
+ else if (type == ECORE_CON_REMOTE_SYSTEM)
+ {
+ svr->fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (svr->fd < 0) goto error;
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
+ lin.l_onoff = 1;
+ lin.l_linger = 100;
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) <
0) goto error;
+ socket_addr.sin_family = AF_INET;
+ socket_addr.sin_port = htons(port);
+ socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ if (bind(svr->fd, (struct sockaddr *)&socket_addr, sizeof(struct sockaddr_in))
< 0) goto error;
+ if (listen(svr->fd, 4096) < 0) goto error;
+ svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
+ ECORE_FD_READ,
+ _ecore_con_svr_handler, svr,
+ NULL, NULL);
+ if (!svr->fd_handler) goto error;
+ }
svr->name = strdup(name);
if (!svr->name) goto error;
@@ -176,6 +198,7 @@
{
Ecore_Con_Server *svr;
struct sockaddr_un socket_unix;
+ struct sockaddr_in socket_addr;
int curstate;
char buf[4096];
@@ -206,7 +229,7 @@
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate))
< 0) goto error;
socket_unix.sun_family = AF_UNIX;
strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
- if (connect(svr->fd, (struct sockaddr *)&socket_unix, SUN_LEN(&socket_unix)) <
0) goto error;
+ if (connect(svr->fd, (struct sockaddr *)&socket_unix,
LENGTH_OF_SOCKADDR_UN(&socket_unix)) < 0) goto error;
svr->path = strdup(buf);
if (!svr->path) goto error;
svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
@@ -215,6 +238,38 @@
NULL, NULL);
if (!svr->fd_handler) goto error;
}
+ else if (type == ECORE_CON_REMOTE_SYSTEM)
+ {
+ struct hostent *he;
+
+ /* FIXME: gethostbyname is blocking... */
+ if (!(he = gethostbyname(name))) goto error;
+ svr->fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (svr->fd < 0) goto error;
+ if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
+ if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
+ if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate))
< 0) goto error;
+ socket_addr.sin_family = AF_INET;
+ socket_addr.sin_port = htons(port);
+ memcpy((struct in_addr *)&socket_addr.sin_addr,
+ he->h_addr, sizeof(struct in_addr));
+ if (connect(svr->fd, (struct sockaddr *)&socket_addr, sizeof(struct
sockaddr_in)) < 0)
+ {
+ if (errno != EINPROGRESS)
+ goto error;
+ svr->connecting = 1;
+ svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
+ ECORE_FD_READ |
ECORE_FD_WRITE,
+ _ecore_con_cl_handler, svr,
+ NULL, NULL);
+ }
+ else
+ svr->fd_handler = ecore_main_fd_handler_add(svr->fd,
+ ECORE_FD_READ,
+ _ecore_con_cl_handler, svr,
+ NULL, NULL);
+ if (!svr->fd_handler) goto error;
+ }
svr->name = strdup(name);
if (!svr->name) goto error;
@@ -358,7 +413,7 @@
servers = _ecore_list_remove(servers, svr);
while (svr->clients)
_ecore_con_client_free((Ecore_Con_Client *)svr->clients);
- unlink(svr->path);
+ if ((svr->created) && (svr->path)) unlink(svr->path);
if (svr->fd >= 0) close(svr->fd);
if (svr->name) free(svr->name);
if (svr->path) free(svr->path);
@@ -460,7 +515,7 @@
}
if ((errno == EIO) || (errno == EBADF) ||
(errno == EPIPE) || (errno == EINVAL) ||
- (errno == ENOSPC))
+ (errno == ENOSPC) || (num == 0)/* is num == 0 right? */)
{
/* we lost our server! */
Ecore_Con_Event_Server_Del *e;
@@ -487,7 +542,42 @@
}
}
else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
- _ecore_con_server_flush(svr);
+ {
+ if (svr->connecting)
+ {
+ int so_err;
+ socklen_t size;
+
+ svr->connecting = 0;
+ so_err = 0;
+ size = sizeof(int);
+ if (getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, &so_err, &size) < 0) so_err
= -1;
+ if (so_err != 0)
+ {
+ /* we lost our server! */
+ Ecore_Con_Event_Server_Del *e;
+
+ e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
+ if (e)
+ {
+ e->server = svr;
+ ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
+ _ecore_con_event_server_del_free, NULL);
+ }
+ svr->dead = 1;
+ ecore_main_fd_handler_del(svr->fd_handler);
+ svr->fd_handler = NULL;
+ ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
+ return 1;
+ }
+ else
+ {
+ if (!svr->buf)
+ ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
+ }
+ }
+ _ecore_con_server_flush(svr);
+ }
return 1;
}
@@ -508,6 +598,7 @@
char buf[65536];
int num;
+ errno = 0;
num = read(cl->fd, buf, 65536);
if (num < 1)
{
@@ -527,7 +618,7 @@
}
if ((errno == EIO) || (errno == EBADF) ||
(errno == EPIPE) || (errno == EINVAL) ||
- (errno == ENOSPC))
+ (errno == ENOSPC) || (num == 0)/* is num == 0 right? */)
{
/* we lost our client! */
Ecore_Con_Event_Client_Del *e;
===================================================================
RCS file:
/cvsroot/enlightenment/e17/libs/ecore/src/lib/ecore_con/Attic/ecore_con_private.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -3 -r1.1.2.2 -r1.1.2.3
--- ecore_con_private.h 13 Mar 2003 05:32:23 -0000 1.1.2.2
+++ ecore_con_private.h 17 Mar 2003 07:33:57 -0000 1.1.2.3
@@ -43,6 +43,7 @@
unsigned char *buf;
char dead : 1;
char created : 1;
+ char connecting : 1;
};
#endif
-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open!
Get cracking and register here for some mind boggling fun and
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs