PERFORCE change 134905 for review
Alexey Tarasov
taleks at FreeBSD.org
Wed Feb 6 06:07:28 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=134905
Change 134905 by taleks at taleks_th on 2008/02/06 14:06:35
Added PXE_SOCK_NONBLOCKING flag for pxe_recv() function.
Also included some stub functions for telnet client.
Affected files ...
.. //depot/projects/soc2007/taleks-pxe_http/httpfs.c#11 edit
.. //depot/projects/soc2007/taleks-pxe_http/ptelnet/README#1 add
.. //depot/projects/soc2007/taleks-pxe_http/ptelnet/pxe_telnet.c#1 add
.. //depot/projects/soc2007/taleks-pxe_http/ptelnet/pxe_telnet.h#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#11 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#8 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#14 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_ip6.h#1 add
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#21 edit
.. //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#18 edit
Differences ...
==== //depot/projects/soc2007/taleks-pxe_http/httpfs.c#11 (text+ko) ====
@@ -31,6 +31,7 @@
#include "pxe_core.h"
#include "pxe_http.h"
#include "pxe_ip.h"
+#include "pxe_sock.h"
static int http_open(const char *path, struct open_file *f);
static int http_close(struct open_file *f);
@@ -180,7 +181,7 @@
/* read all we have in buffer */
if (httpfile->cache_size != 0) {
part1 = pxe_recv(httpfile->socket, addr2,
- httpfile->cache_size);
+ httpfile->cache_size, PXE_SOCK_BLOCKING);
#ifdef PXE_HTTP_DEBUG_HELL
printf("http_read(): cache -> %ld/%lu/%lu/%u bytes\n",
part1, to_read, size, httpfile->cache_size);
@@ -236,7 +237,7 @@
return (EINVAL);
}
- result = pxe_recv(httpfile->socket, addr2, to_read);
+ result = pxe_recv(httpfile->socket, addr2, to_read, PXE_SOCK_BLOCKING);
#ifdef PXE_HTTP_DEBUG_HELL
printf("http_read(): cache > %ld/%lu/%lu/%u bytes\n",
result, to_read, size, httpfile->cache_size);
@@ -335,7 +336,7 @@
}
#ifdef PXE_HTTPFS_CACHING
/* if we seeked somewhere, cache failed, need clean it */
- pxe_recv(httpfile->socket, httpfile->cache_size, NULL);
+ pxe_recv(httpfile->socket, httpfile->cache_size, NULL, PXE_SOCK_BLOCKING);
httpfile->cache_size = 0;
#endif
return (httpfile->offset);
==== //depot/projects/soc2007/taleks-pxe_http/pxe_dhcp.c#11 (text+ko) ====
@@ -370,7 +370,7 @@
case PXE_AWAIT_NEWPACKETS:
/* some packets were received, need checking our socket */
size = pxe_recv(wait_data->socket, wait_data->data,
- wait_data->size);
+ wait_data->size, PXE_SOCK_NONBLOCKING);
if ( size > 0) {
/* something felt to socket */
==== //depot/projects/soc2007/taleks-pxe_http/pxe_dns.c#8 (text+ko) ====
@@ -488,7 +488,7 @@
case PXE_AWAIT_NEWPACKETS:
size = pxe_recv(wait_data->socket, wait_data->data,
- wait_data->size);
+ wait_data->size, PXE_SOCK_NONBLOCKING);
if (size > 0) {
#ifdef PXE_DEBUG
==== //depot/projects/soc2007/taleks-pxe_http/pxe_http.c#14 (text+ko) ====
@@ -140,7 +140,8 @@
char ch = '\0';
while (count < maxsize - 1) {
- result = pxe_recv(socket, &data[count], maxsize - 1 - count);
+ result = pxe_recv(socket, &data[count], maxsize - 1 - count,
+ PXE_SOCK_BLOCKING);
if (result == -1) { /* failed to recv */
#ifdef PXE_HTTP_DEBUG_HELL
@@ -205,7 +206,7 @@
char ch = '\0';
while (count < maxsize - 1) {
- result = pxe_recv(socket, &data[count], 1);
+ result = pxe_recv(socket, &data[count], 1, PXE_SOCK_BLOCKING);
if (result == -1) { /* failed to recv */
#ifdef PXE_HTTP_DEBUG_HELL
@@ -394,7 +395,8 @@
printf("%s", found + 4);
while (1) {
- result = pxe_recv(socket, http_data, PXE_MAX_HTTP_HDRLEN - 1);
+ result = pxe_recv(socket, http_data, PXE_MAX_HTTP_HDRLEN - 1,
+ PXE_SOCK_BLOCKING);
if (result == -1)
break;
@@ -563,7 +565,7 @@
while (count < size_to_get) {
result = pxe_recv(hh->socket, buffer + count,
- size_to_get - count);
+ size_to_get - count, PXE_SOCK_BLOCKING);
if (result == -1)
break;
@@ -737,7 +739,8 @@
pxe_memcpy((char *)found + 4, buffer, count);
while (count < size_to_get) {
- result = pxe_recv(socket, buffer + count, size_to_get - count);
+ result = pxe_recv(socket, buffer + count, size_to_get - count,
+ PXE_SOCK_BLOCKING);
if (result == -1)
break;
==== //depot/projects/soc2007/taleks-pxe_http/pxe_sock.c#21 (text+ko) ====
@@ -548,12 +548,13 @@
* socket - socket descriptor number to recieve data from
* tobuf - buffer to receive data to
* buflen - size of buffer
+ * flags - PXE_SOCK... flags
* out:
* -1 - failure
* nonnegative - actual count of bytes received
*/
int
-pxe_recv(int socket, void *tobuf, uint16_t buflen)
+pxe_recv(int socket, void *tobuf, uint16_t buflen, int flags)
{
#ifdef PXE_SOCKET_ACCURATE
if ( (socket >= PXE_DEFAULT_SOCKETS) || (socket == -1)) {
@@ -595,7 +596,7 @@
result = pxe_tcp_read(sock, tobuf, buflen);
}
- if (result != 0)
+ if ((result != 0) || (flags == PXE_SOCK_NONBLOCKING))
break;
if (timer > PXE_SOCKET_TIMEOUT)
@@ -629,12 +630,13 @@
* tobuf - buffer to receive data to
* buflen - size of buffer
* src_ip - pointer to memory, where store IP of sender
+ * flags - one of PXE_SOCK... flags
* out:
* -1 - failure
* nonnegative - actual count of bytes received
*/
int
-pxe_recvfrom(int socket, void *tobuf, size_t buflen, uint32_t *src_ip)
+pxe_recvfrom(int socket, void *tobuf, size_t buflen, uint32_t *src_ip, int flags)
{
#ifdef PXE_SOCKET_ACCURATE
if ( (socket >= PXE_DEFAULT_SOCKETS) || (socket == -1)) {
@@ -677,7 +679,7 @@
result = pxe_tcp_read(sock, tobuf, buflen);
}
- if (result != 0)
+ if ((result != 0) || (flags == PXE_SOCK_NONBLOCKING))
break;
if (timer > PXE_SOCKET_TIMEOUT)
==== //depot/projects/soc2007/taleks-pxe_http/pxe_sock.h#18 (text+ko) ====
@@ -61,6 +61,9 @@
/* connection established. TODO: check if need */
#define PXE_SOCKET_ESTABLISHED 0x4
+#define PXE_SOCK_NONBLOCKING 0
+#define PXE_SOCK_BLOCKING 1
+
/* socket */
typedef struct pxe_socket {
PXE_BUFFER send_buffer; /* sending buffer */
@@ -121,7 +124,7 @@
int pxe_send(int socket, void *buf, uint16_t buflen);
/* receive data from socket, blocking */
-int pxe_recv(int socket, void *buf, uint16_t buflen);
+int pxe_recv(int socket, void *buf, uint16_t buflen, int flags);
/* create new socket */
int pxe_socket();
More information about the p4-projects
mailing list