Follow us on Google+ Follow us on Facebook Follow us on Twitter

Changeset mainline,1319


Ignore:
Timestamp:
2011-12-09T23:30:36Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
branch-nick:
main-clone
parents:
RevTreeChgset
1318@mainline,1318[mainline,1318]
1234.1.39@mainline,1234.1.39[mainline,1234.1.39]
revision id:
jiri@wiwaxia-20111209233036-l4qbc7hmeg25z9l1
Message:

Merge TCP rewrite.

Location:
mainline
Files:
31 added
3 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • mainline/boot/Makefile.common

    r1306 r1319  
    174174        $(USPACE_PATH)/app/nettest1/nettest1 \
    175175        $(USPACE_PATH)/app/nettest2/nettest2 \
     176        $(USPACE_PATH)/app/nettest3/nettest3 \
    176177        $(USPACE_PATH)/app/netecho/netecho \
    177178        $(USPACE_PATH)/app/ping/ping \
  • mainline/uspace/Makefile

    r1283 r1319  
    6464        app/nettest1 \
    6565        app/nettest2 \
     66        app/nettest3 \
    6667        app/ping \
    6768        app/websrv \
  • mainline/uspace/app/netecho/netecho.c

    r783 r4.1.28  
    241241                /* Accept a socket if a stream socket is used */
    242242                addrlen = sizeof(address_buf);
     243                if (verbose)
     244                        printf("accept()\n");
    243245                socket_id = accept(listening_id, (void *) address_buf, &addrlen);
    244246                if (socket_id <= 0) {
     
    258260
    259261                /* Receive a message to echo */
     262                if (verbose)
     263                        printf("recvfrom()\n");
    260264                rcv_size = recvfrom(socket_id, data, size, 0, address,
    261265                    &addrlen);
     
    297301
    298302                        /* Answer the request either with the static reply or the original data */
    299                         rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen);
    300                         if (rc != EOK)
    301                                 socket_print_error(stderr, rc, "Socket send: ", "\n");
     303                        if (type == SOCK_STREAM) {
     304                                if (verbose)
     305                                        printf("send()\n");
     306                                rc = send(socket_id, reply ? reply : data, reply ? reply_length : length, 0);
     307                                if (rc != EOK)
     308                                        socket_print_error(stderr, rc, "Socket send: ", "\n");
     309                        } else {
     310                                if (verbose)
     311                                        printf("sendto()\n");
     312                                rc = sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen);
     313                                if (rc != EOK)
     314                                        socket_print_error(stderr, rc, "Socket send: ", "\n");
     315                        }
    302316                }
    303317
  • mainline/uspace/drv/nic/ne2k/dp8390.c

    r1269 r1319  
    142142static void ne2k_upload(ne2k_t *ne2k, void *buf, size_t addr, size_t size)
    143143{
     144        size_t esize_ru = (size + 1) & ~1;
    144145        size_t esize = size & ~1;
    145146       
    146         pio_write_8(ne2k->port + DP_RBCR0, esize & 0xff);
    147         pio_write_8(ne2k->port + DP_RBCR1, (esize >> 8) & 0xff);
     147        pio_write_8(ne2k->port + DP_RBCR0, esize_ru & 0xff);
     148        pio_write_8(ne2k->port + DP_RBCR1, (esize_ru >> 8) & 0xff);
    148149        pio_write_8(ne2k->port + DP_RSAR0, addr & 0xff);
    149150        pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff);
  • mainline/uspace/lib/c/generic/fibril_synch.c

    r1048 r4.1.14  
    447447}
    448448
     449/** Timer fibril.
     450 *
     451 * @param arg   Timer
     452 */
     453static int fibril_timer_func(void *arg)
     454{
     455        fibril_timer_t *timer = (fibril_timer_t *) arg;
     456        int rc;
     457
     458        fibril_mutex_lock(&timer->lock);
     459
     460        while (true) {
     461                while (timer->state != fts_active &&
     462                    timer->state != fts_cleanup) {
     463
     464                        if (timer->state == fts_cleanup)
     465                                break;
     466
     467                        fibril_condvar_wait(&timer->cv, &timer->lock);
     468                }
     469
     470                if (timer->state == fts_cleanup)
     471                        break;
     472
     473                rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock,
     474                    timer->delay);
     475                if (rc == ETIMEOUT) {
     476                        timer->state = fts_fired;
     477                        fibril_mutex_unlock(&timer->lock);
     478                        timer->fun(timer->arg);
     479                        fibril_mutex_lock(&timer->lock);
     480                }
     481        }
     482
     483        fibril_mutex_unlock(&timer->lock);
     484        return 0;
     485}
     486
     487/** Create new timer.
     488 *
     489 * @return              New timer on success, @c NULL if out of memory.
     490 */
     491fibril_timer_t *fibril_timer_create(void)
     492{
     493        fid_t fid;
     494        fibril_timer_t *timer;
     495
     496        timer = calloc(1, sizeof(fibril_timer_t));
     497        if (timer == NULL)
     498                return NULL;
     499
     500        fid = fibril_create(fibril_timer_func, (void *) timer);
     501        if (fid == 0) {
     502                free(timer);
     503                return NULL;
     504        }
     505
     506        fibril_mutex_initialize(&timer->lock);
     507        fibril_condvar_initialize(&timer->cv);
     508
     509        timer->fibril = fid;
     510        timer->state = fts_not_set;
     511
     512        fibril_add_ready(fid);
     513
     514        return timer;
     515}
     516
     517/** Destroy timer.
     518 *
     519 * @param timer         Timer, must not be active or accessed by other threads.
     520 */
     521void fibril_timer_destroy(fibril_timer_t *timer)
     522{
     523        fibril_mutex_lock(&timer->lock);
     524        assert(timer->state != fts_active);
     525        timer->state = fts_cleanup;
     526        fibril_condvar_broadcast(&timer->cv);
     527        fibril_mutex_unlock(&timer->lock);
     528}
     529
     530/** Set timer.
     531 *
     532 * Set timer to execute a callback function after the specified
     533 * interval.
     534 *
     535 * @param timer         Timer
     536 * @param delay         Delay in microseconds
     537 * @param fun           Callback function
     538 * @param arg           Argument for @a fun
     539 */
     540void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay,
     541    fibril_timer_fun_t fun, void *arg)
     542{
     543        fibril_mutex_lock(&timer->lock);
     544        timer->state = fts_active;
     545        timer->delay = delay;
     546        timer->fun = fun;
     547        timer->arg = arg;
     548        fibril_condvar_broadcast(&timer->cv);
     549        fibril_mutex_unlock(&timer->lock);
     550}
     551
     552/** Clear timer.
     553 *
     554 * Clears (cancels) timer and returns last state of the timer.
     555 * This can be one of:
     556 *    - fts_not_set     If the timer has not been set or has been cleared
     557 *    - fts_active      Timer was set but did not fire
     558 *    - fts_fired       Timer fired
     559 *
     560 * @param timer         Timer
     561 * @return              Last timer state
     562 */
     563fibril_timer_state_t fibril_timer_clear(fibril_timer_t *timer)
     564{
     565        fibril_timer_state_t old_state;
     566
     567        fibril_mutex_lock(&timer->lock);
     568        old_state = timer->state;
     569        timer->state = fts_not_set;
     570
     571        timer->delay = 0;
     572        timer->fun = NULL;
     573        timer->arg = NULL;
     574        fibril_condvar_broadcast(&timer->cv);
     575        fibril_mutex_unlock(&timer->lock);
     576
     577        return old_state;
     578}
     579
    449580/** @}
    450581 */
  • mainline/uspace/lib/c/include/bitops.h

    r1083 r4.1.19  
    4040/** Mask with bit @a n set. */
    4141#define BIT_V(type, n) \
    42     ((type)1 << ((n) - 1))
     42    ((type)1 << (n))
    4343
    4444/** Mask with rightmost @a n bits set. */
    4545#define BIT_RRANGE(type, n) \
    46     (BIT_V(type, (n) + 1) - 1)
     46    (BIT_V(type, (n)) - 1)
    4747
    4848/** Mask with bits @a hi .. @a lo set. @a hi >= @a lo. */
  • mainline/uspace/lib/c/include/errno.h

    r7.1.14 r4.1.23  
    9696#define ENOTCONN  (-10057)
    9797
     98#define ECONNREFUSED  (-10058)
     99
     100#define ECONNABORTED  (-10059)
     101
    98102/** The requested operation was not performed. Try again later. */
    99103#define EAGAIN  (-11002)
  • mainline/uspace/lib/c/include/fibril_synch.h

    r1048 r4.1.12  
    107107        fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
    108108
     109typedef void (*fibril_timer_fun_t)(void *);
     110
     111typedef enum {
     112        /** Timer has not been set or has been cleared */
     113        fts_not_set,
     114        /** Timer was set but did not fire yet */
     115        fts_active,
     116        /** Timer has fired and has not been cleared since */
     117        fts_fired,
     118        /** Timer is being destroyed */
     119        fts_cleanup
     120} fibril_timer_state_t;
     121
     122/** Fibril timer.
     123 *
     124 * When a timer is set it executes a callback function (in a separate
     125 * fibril) after a specified time interval. The timer can be cleared
     126 * (canceled) before that. From the return value of fibril_timer_clear()
     127 * one can tell whether the timer fired or not.
     128 */
     129typedef struct {
     130        fibril_mutex_t lock;
     131        fibril_condvar_t cv;
     132        fid_t fibril;
     133        fibril_timer_state_t state;
     134
     135        suseconds_t delay;
     136        fibril_timer_fun_t fun;
     137        void *arg;
     138} fibril_timer_t;
     139
    109140extern void fibril_mutex_initialize(fibril_mutex_t *);
    110141extern void fibril_mutex_lock(fibril_mutex_t *);
     
    129160extern void fibril_condvar_broadcast(fibril_condvar_t *);
    130161
     162extern fibril_timer_t *fibril_timer_create(void);
     163extern void fibril_timer_destroy(fibril_timer_t *);
     164extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t,
     165    void *);
     166extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
     167
    131168#endif
    132169
  • mainline/uspace/srv/net/tl/tcp/Makefile

    r822 r4.1.22  
    11#
    2 # Copyright (c) 2005 Martin Decky
    3 # Copyright (c) 2007 Jakub Jermar
     2# Copyright (c) 2011 Jiri Svoboda
    43# All rights reserved.
    54#
     
    3433
    3534SOURCES = \
    36         tcp.c
     35        conn.c \
     36        iqueue.c \
     37        ncsim.c \
     38        pdu.c \
     39        rqueue.c \
     40        segment.c \
     41        seq_no.c \
     42        sock.c \
     43        tcp.c \
     44        test.c \
     45        tqueue.c \
     46        ucall.c
    3747
    3848include $(USPACE_PREFIX)/Makefile.common
Note: See TracChangeset for help on using the changeset viewer.