Changeset c23a1fe in mainline for uspace/srv/hid/remcons/user.c


Ignore:
Timestamp:
2024-09-26T22:24:43Z (2 weeks ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
89e5c0c7
Parents:
09f41d3
Message:

Remote console mapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/remcons/user.c

    r09f41d3 rc23a1fe  
    3838#include <adt/prodcons.h>
    3939#include <errno.h>
     40#include <macros.h>
    4041#include <mem.h>
    4142#include <str_error.h>
     
    8687        user->socket_buffer_len = 0;
    8788        user->socket_buffer_pos = 0;
     89        user->send_buf_used = 0;
    8890
    8991        fibril_condvar_initialize(&user->refcount_cv);
     
    370372}
    371373
     374static errno_t telnet_user_send_raw(telnet_user_t *user,
     375    const void *data, size_t size)
     376{
     377        size_t remain;
     378        size_t now;
     379        errno_t rc;
     380
     381        remain = sizeof(user->send_buf) - user->send_buf_used;
     382        while (size > 0) {
     383                if (remain == 0) {
     384                        rc = tcp_conn_send(user->conn, user->send_buf,
     385                            sizeof(user->send_buf));
     386                        if (rc != EOK)
     387                                return rc;
     388
     389                        user->send_buf_used = 0;
     390                        remain = sizeof(user->send_buf);
     391                }
     392
     393                now = min(remain, size);
     394                memcpy(user->send_buf + user->send_buf_used, data, now);
     395                user->send_buf_used += now;
     396                remain -= now;
     397                data += now;
     398                size -= now;
     399        }
     400
     401        return EOK;
     402}
     403
    372404/** Send data (convert them first) to the socket, no locking.
    373405 *
     
    389421                        converted[converted_size++] = 10;
    390422                        user->cursor_x = 0;
    391                         if (user->cursor_y < user->rows - 1)
     423                        if (user->cursor_y < (int)user->rows - 1)
    392424                                ++user->cursor_y;
    393425                } else {
     
    401433        }
    402434
    403         errno_t rc = tcp_conn_send(user->conn, converted, converted_size);
     435        errno_t rc = telnet_user_send_raw(user, converted, converted_size);
    404436        free(converted);
    405437
     
    423455
    424456        return rc;
     457}
     458
     459errno_t telnet_user_flush(telnet_user_t *user)
     460{
     461        errno_t rc;
     462
     463        fibril_mutex_lock(&user->guard);
     464        rc = tcp_conn_send(user->conn, user->send_buf, user->send_buf_used);
     465
     466        if (rc != EOK) {
     467                fibril_mutex_unlock(&user->guard);
     468                return rc;
     469        }
     470
     471        user->send_buf_used = 0;
     472        fibril_mutex_unlock(&user->guard);
     473        return EOK;
    425474}
    426475
Note: See TracChangeset for help on using the changeset viewer.