muse_builtin_networking.c File Reference

#include "muse_opcodes.h"
#include "muse_port.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

Include dependency graph for muse_builtin_networking.c:


Data Structures

struct  socketport_t
struct  muse_server_stream_socket__
struct  multicast_socket_port_t

Point to point communication

Made possible through the functions

typedef muse_server_stream_socket__ muse_server_stream_socket_t
muse_cell fn_with_connection_to_server (muse_env *env, void *context, muse_cell args)
 (with-connection-to-server server-port-string service-fn).
muse_cell fn_with_incoming_connections_to_port (muse_env *env, void *context, muse_cell args)
 (with-incoming-connections-to-port port-number service-fn).
static void socket_init (void *s, muse_cell args)
static void socket_close (void *s)
static void socket_destroy (void *s)
static size_t socket_read (void *buffer, size_t nbytes, void *s)
static size_t socket_write (void *buffer, size_t nbytes, void *s)
static int socket_flush (void *s)
static muse_cell fn_network_client_receive (muse_env *env, void *context, muse_cell args)
static muse_cell fn_network_client_send (muse_env *env, void *context, muse_cell args)
static muse_port_type_t g_socket_type

Multicast messaging

A simple multicast mechanism is implemented using UDP datagrams. You join a multicast group by creating a muSE port using the function multicast-group. Once the join succeeds, you can broadcast a message to the group and can receive broadcast messages from any member of the group using the standard read and write functions.

Immediately after a read, information about the sender is stored internally and you can reply to the sender alone by using the reply function. reply works only with multicast group ports. It is a programming error to use it with other ports.

You can use the wait-for-input function to wait for a message from a multicast group as well.

muse_cell fn_multicast_group (muse_env *env, void *context, muse_cell args)
 (multicast-group [address] [port]).
muse_cell fn_reply (muse_env *env, void *context, muse_cell args)
 (reply port).
muse_cell fn_multicast_group_p (muse_env *env, void *context, muse_cell args)
 (multicast-group? p).
static void multicast_socket_init (void *p, muse_cell args)
static void multicast_socket_close (void *p)
static void multicast_socket_destroy (void *p)
static size_t multicast_socket_read (void *buffer, size_t nbytes, void *p)
static size_t multicast_socket_write (void *buffer, size_t nbytes, void *p)
static int multicast_socket_flush (void *p)
static muse_port_type_t g_multicast_socket_type

Defines

#define SOCKET   int
#define SOCKET_ERROR   (-1)
#define INVALID_SOCKET   (-1)
#define closesocket(x)   close(x)
#define MUSE_DEFAULT_MULTICAST_PORT   31415
#define MUSE_DEFAULT_MULTICAST_GROUP   "231.41.59.26"
#define MUSE_SO_REUSE   SO_REUSEPORT
 On MacosX, it looks like we have to use SO_REUSEPORT instead of SO_REUSEADDR to achieve the same effect.

Functions

muse_boolean muse_network_startup ()
 In the POSIX version, we initially setup to block the SIGPIPE signal.
void muse_network_shutdown ()
muse_cell fn_wait_for_input (muse_env *env, void *context, muse_cell args)
 (wait-for-input network-port [timeout-microseconds]).
static muse_cell fn_network_shutdown (muse_env *env, void *context, muse_cell args)
 Shutsdown the socket API.
void muse_define_builtin_networking ()

Detailed Description

Author:
Srikumar K. S. (mailto:kumar@muvee.com)
Copyright (c) 2006 Jointly owned by Srikumar K. S. and muvee Technologies Pte. Ltd.

All rights reserved. See LICENSE.txt distributed with this source code or http://muvee-symbolic-expressions.googlecode.com/svn/trunk/LICENSE.txt for terms and conditions under which this software is provided to you.


Define Documentation

#define SOCKET   int

#define SOCKET_ERROR   (-1)

#define INVALID_SOCKET   (-1)

#define closesocket (  )     close(x)

#define MUSE_DEFAULT_MULTICAST_PORT   31415

#define MUSE_DEFAULT_MULTICAST_GROUP   "231.41.59.26"

#define MUSE_SO_REUSE   SO_REUSEPORT

On MacosX, it looks like we have to use SO_REUSEPORT instead of SO_REUSEADDR to achieve the same effect.


Typedef Documentation

typedef struct muse_server_stream_socket__ muse_server_stream_socket_t


Function Documentation

static void socket_init ( void *  s,
muse_cell  args 
) [static]

static void socket_close ( void *  s  )  [static]

static void socket_destroy ( void *  s  )  [static]

static size_t socket_read ( void *  buffer,
size_t  nbytes,
void *  s 
) [static]

static size_t socket_write ( void *  buffer,
size_t  nbytes,
void *  s 
) [static]

static int socket_flush ( void *  s  )  [static]

static muse_cell fn_network_client_receive ( muse_env env,
void *  context,
muse_cell  args 
) [static]

static muse_cell fn_network_client_send ( muse_env env,
void *  context,
muse_cell  args 
) [static]

static muse_cell fn_network_shutdown ( muse_env env,
void *  context,
muse_cell  args 
) [static]

Shutsdown the socket API.

No need to call this as its called at GC time when the muse environment is destroyed.

void muse_define_builtin_networking (  ) 


Variable Documentation

muse_port_type_t g_socket_type [static]

Initial value:

{
    {
        'muSE',
        'port',
        sizeof(socketport_t),
        NULL,
        NULL,
        socket_init,
        NULL,
        socket_destroy,
        NULL
    },
    
    socket_close,
    socket_read,
    socket_write,
    socket_flush
}


Generated on Mon Sep 25 23:12:47 2006 for muSE by  doxygen 1.4.7